Link to home
Start Free TrialLog in
Avatar of Derokorian
DerokorianFlag for United States of America

asked on

PHPMailer + Gmail - No route to host (113)

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):

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

Open in new window


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

<?php
   $mail->SMTPSecure = "tls";
   $mail->Host       = "smtp.gmail.com";
   $mail->Port       = 587;

Open in new window


I was using http://phpmailer.worxware.com/index....=examplebgmail 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
Avatar of Derokorian
Derokorian
Flag of United States of America image

ASKER

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       = "smtp.gmail.com";
   $mail->Port       = 465;

Open in new window

Thought this should be @gmail.com?

$mail->Username   = "username@gmail.com";
$mail->Password   = "password of the gmail account";


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

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

;; QUESTION SECTION:
;noas.com.                      IN      MX

;; ANSWER SECTION:
noas.com.               108666  IN      MX      10 ASPMX.L.GOOGLE.com.
noas.com.               108666  IN      MX      20 ALT1.ASPMX.L.GOOGLE.com.
noas.com.               108666  IN      MX      30 ALT2.ASPMX.L.GOOGLE.com.
noas.com.               108666  IN      MX      40 ASPMX2.GOOGLEMAIL.com.
noas.com.               108666  IN      MX      50 ASPMX3.GOOGLEMAIL.com.

;; AUTHORITY SECTION:
noas.com.               3543    IN      NS      ns51.domaincontrol.com.
noas.com.               3543    IN      NS      ns52.domaincontrol.com.

;; Query time: 1 msec
;; SERVER: 10.1.0.3#53(10.1.0.3)
;; WHEN: Fri Aug  5 09:06:21 2011
;; MSG SIZE  rcvd: 208

Open in new window

Avatar of Daniel McAllister
"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...


Dan
IT4SOHO
SOLUTION
Avatar of crazedsanity
crazedsanity
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 mail.noas.com 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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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; rackspace.com charges ~$200 for about the same.

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