SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: xxxxx@gmail.com ERROR

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: xxxxx@gmail.com ERROR

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding the Gmail SMTP Timeout in Shared Hosting Environments

When a contact form works perfectly on localhost but fails immediately upon deployment to a live server, the issue almost always lies outside your application logic and inside your hosting environment or external API policies. The error message SMTP -> ERROR: Failed to connect to server: Connection timed out (110) combined with the failure of the "From" address (xxxxxx@gmail.com) points to a specific conflict between Gmail's security architecture and how shared hosting servers handle outbound traffic.

The core problem is not that your PHPMailer configuration is syntactically incorrect; it is that you are attempting to authenticate as a third-party Google account from an untrusted network. When running on localhost, the connection originates from your personal machine, which Google may recognize or treat with leniency depending on your local security settings. However, when hosted, the request originates from the shared hosting provider's IP address range. Gmail has strict policies regarding "less secure apps" and unauthorized access to accounts that are not explicitly authorized for that specific domain.

The Authentication Failure Trap

In the provided code snippet, the configuration attempts to use SMTPAuth = true with a username and password. Historically, PHPMailer supported two primary methods for Gmail authentication:

  1. App Passwords: A 16-character string generated within your Google Account settings under "Security". This is required if you have enabled Two-Factor Authentication (2FA) or if your account is flagged for suspicious activity.
  2. OAuth2: The modern standard, though often more complex to set up in legacy PHPMailer versions like 5.2.1 without additional libraries.

If you are using your standard account password, Gmail's security systems will likely block the connection from the hosting server's IP. This results in a timeout or an immediate rejection. The error code 110 typically indicates a TCP connection failure where the SMTP handshake could not be completed before the socket was closed or timed out. This often happens because the server hangs on the authentication attempt, waiting for a response that never comes due to Gmail's firewall dropping packets from unknown IPs.

Verifying Host Restrictions

Before adjusting your code, you must verify if the hosting provider allows outbound connections to port 587. Some shared hosting plans restrict SMTP traffic to specific ports (often just 25) or block it entirely to prevent servers from being used as spam relays. If smtp.gmail.com is blocked at the firewall level on the host, the connection will never initiate, resulting in a timeout.

You can test this by attempting to connect to the port using a command-line tool like nc (netcat):

nc -zv smtp.gmail.com 587

If the connection hangs indefinitely or is refused, your hosting provider has blocked the port. You will need to contact them to whitelist outbound SMTP traffic or switch to a provider that offers this capability.

The "From" Address Mismatch

The error log explicitly states: The following From address failed: xxxxx@gmail.com. This is a critical security flag from Gmail. Even if authentication succeeds, Gmail requires that the sender's email address be verified within the account used for authentication. If the code attempts to send an email from user@gmail.com but authenticates as admin@hosting-domain.com, or vice versa without proper verification, the server will reject the command.

In your configuration:

$mail->SetFrom($email, $name);
$mail->Username = "xxxx@gmail.com"; 

Ensure that the $email variable used in SetFrom matches exactly the username being used for SMTP authentication. Mismatches here trigger immediate blocks to prevent spoofing.

Recommended Resolution Strategy

The most robust solution is to generate an App Password from your Google Account settings. This bypasses the need for your main account password and grants permission specifically for mail applications. Once generated, use this unique password in your $mail->Password variable.

Alternatively, consider migrating away from PHPMailer's built-in SMTP handler for Gmail if you cannot secure App Passwords. Services like Mailgun, SendGrid, or Postmark provide dedicated API keys that do not rely on personal Google account credentials and often offer better deliverability rates for transactional emails. They also handle the DNS records (SPF, DKIM) required to ensure your emails land in the inbox rather than the spam folder.

Finally, if you are using Laravel, you might consider utilizing the built-in mail() helper or a package like spatie/laravel-mail which simplifies these configurations and handles queueing for better performance. However, for raw PHP scripts, ensuring the authentication method matches Gmail's current security requirements is the definitive fix.

Our network