PHPMailer + Gmail - No route to host (113)

Derokorian used Ask the Experts™
Ok So I'm trying to update old code to use SMTP authentication through our GMail hosted company email. I'm running into the following error:

SMTP -> ERROR: Failed to connect to server: No route to host (113)
SMTP Error: Could not connect to SMTP host.
My code is (note some things sanitized for public viewing):

   $paths = get_include_path();
   set_include_path($paths . PATH_SEPARATOR . dirname(__FILE__) . '/phpmailer');
   $mail = new phpmailer;
   // Constant email settings.
   $mail->SMTPAuth   = TRUE;
   $mail->SMTPSecure = "tls";
   $mail->Host       = "";
   $mail->Port       = 587;
   $mail->Username   = "";
   $mail->Password   = "--";
   $mail->From       = "";
   $mail->FromName   = "NOAS Contact";
   $mail->WordWrap   = 75;
   $mail->Subject    = "10th Anniversary Dave Thomas Celebrity Cookoff - Chef Invite";
   $mail->AddReplyTo("", "--");
      $mail->SMTPDebug = 2; // For debugging, change to 0 when working
   foreach( $emails as $info ) {
      $mail->AddAddress($info['email'], $info['name']);
      // Send mail message to each recipient
      if( $mail->Send() )
         $content .= 'Message to '. $info['name'] .' sent successfully.<br />';
         $content .= 'Message to '. $info['name'] .' failed to send.<br />';

Open in new window

I've also tried changing to this as in a document included:

   $mail->SMTPSecure = "tls";
   $mail->Host       = "";
   $mail->Port       = 587;

Open in new window

I was using plus the documents included in the ZIP to set up the settings, So I don't see what's wrong. Sometimes I get this error instead:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host.

Either way its not sending emails, Any help would be greatly appreciated =D
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


Try to change it to SSL not change it to the exact same thing! Oops my bad, this is what I tried.

   $mail->SMTPSecure = "ssl";
   $mail->Host       = "";
   $mail->Port       = 465;

Open in new window

Thought this should be

$mail->Username   = "";
$mail->Password   = "password of the gmail account";

Port should be 587
The domain "" is a Google Apps domain, so the username syntax is valid:
xxx@lenny:~/www/cs/lib$ dig -t MX

; <<>> DiG 9.7.0-P1 <<>> -t MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37031
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 2, ADDITIONAL: 0

;                      IN      MX

;; ANSWER SECTION:               108666  IN      MX      10               108666  IN      MX      20               108666  IN      MX      30               108666  IN      MX      40               108666  IN      MX      50

;; AUTHORITY SECTION:               3543    IN      NS               3543    IN      NS

;; Query time: 1 msec
;; WHEN: Fri Aug  5 09:06:21 2011
;; MSG SIZE  rcvd: 208

Open in new window

Daniel McAllisterPresident, IT4SOHO, LLC

"No route to host" is the error message...

Why not believe it?

The error doesn't say login failed, or connection error -- it says no route to host.

Not to be snide, but I've found that carefully reading the error message (sometimes all 10 words) often leads me directly to the problem!

To me, this means either that the SMTP server info is bad (including perhaps using the wrong syntax to define the SMTP port), or the port number is wrong, or the server's internal DNS isn't working (check /etc/resolv.conf).

But that's just a first stab.... SOMETHING is screwing up the script's ability to make the SMTP connection at all. Worrying about anything that happens AFTER the initial connection is like trying to pre-set your car stereo before you put in the car battery... (as-in you won't be accomplishing much!)

Just my feeble thoughts on the subject...

Good point, IT4SOHO.  On the server having issues, try doing basic dig/nslookup for the smtp server, or even try pinging (this might be blocked in your network or by the destination server, so don't jump to conclusions if there's no response).


I'm on shared hosting, and am unable to login via SSH to run any command line parameters that way. If there a way to run these tests using PHP?

 I did read the whole error message, and I posted the code producing the message because obviously something isn't right, even tho it matches the info on Google's page, PHPMailers page, and the included documentation. I know the login info is fine, since I can log in to the account via however that doesn't matter its not finding the server at all, and I don't know why! I've tried SSL and TLS to no avail.

Any ideas that would simply help identify the problem would be appreciated even if it doesn't help fix them, but at this point I'm at a loss to even figuring out what's causing the problem. BTW I've now tested this code on my local host machine and it works, so its something on the server. Maybe an INI setting is wrong?
I would suggest contacting your hosting provider.  Explain the problem and the things you've tried, they should be able to help you further.

You might be able to run CLI commands via PHP, using "exec()" or "system()".
The commands you could try are:

Open in new window

I am unable to do a direct connection to
user@lenny:~$ telnet 25
telnet: Unable to connect to remote host: Connection refused

Open in new window


After talking with my hosting provider it seems they BLOCK any external SSL or TLS connections making it impossible to send from GMail. Thanks for your help in identifying the problem, it would seem to be the fault of the host - unfortunately the email relay I would be required to use has a 45-60min delay on sending emails out (which is horrible for reseting passwords) I guess I won't be able to update our invitation system until we change providers.

Thanks for your help, any suggestions on good linux hosting that won't cost to much?
I host my own servers via a home broadband connection, haven't dealt with hosting in other places except for DNS.  I'm not really sure what you mean by "too much" in terms of cost: the best I can find locally as far as dedicated servers is ~$100; charges ~$200 for about the same.

If you're looking at basic web hosting, BTInet (local to ND) charges ~$9/month... see [ ] for more info.  My experience is that they try to stay as transparent as possible in the whole equation.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial