title: PHPMailer's infamous SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed
body: <p>I'm trying to get PHPMailer working using a Google Apps SMTP server. I've tried:</p>
  
  <ol>
  <li>Uncommenting openssl in php.ini</li>
  <li>Telneting Google's server on port 465 (success)</li>
  <li>Telneting my webserver on port 465 (success)</li>
  <li>Telnetting Google's server from my server (success)</li>
  <li>Checking DNS SPF/MX records (and sanitizing to IPv4)</li>
  <li>tls on port 587</li>
  <li>webhost confirms they allow outbound SMTP traffic</li>
  <li>google captcha's unlock trick</li>
  <li>Reading everything I could find on StackOverflow (solutions covered the above)</li>
  </ol>
  
  <p>Can someone provide a solution to the timed out connection?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
  $Mail = new PHPMailer();
  $Mail-&gt;IsSMTP(); // Use SMTP
  $Mail-&gt;Host        = "smtp.gmail.com"; // Sets SMTP server
  $Mail-&gt;SMTPDebug   = 1; // 2 to enable SMTP debug information
  $Mail-&gt;SMTPAuth    = TRUE; // enable SMTP authentication
  $Mail-&gt;SMTPSecure  = "ssl"; //Secure conection
  $Mail-&gt;Port        = 465; // set the SMTP port
  $Mail-&gt;Username    = 'account@googleappsaddress.com'; // SMTP account username
  $Mail-&gt;Password    = 'mypassword'; // SMTP account password
  $Mail-&gt;Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
  $Mail-&gt;CharSet     = 'UTF-8';
  $Mail-&gt;Encoding    = '8bit';
  $Mail-&gt;Subject     = 'Test Email Using Gmail';
  $Mail-&gt;ContentType = 'text/html; charset=utf-8\r\n';
  $Mail-&gt;From        = 'myemail@gmail.com';
  $Mail-&gt;FromName    = 'GMail Test';
  $Mail-&gt;WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line
  
  $Mail-&gt;AddAddress( $to ); // To:
  $Mail-&gt;isHTML( TRUE );
  $Mail-&gt;Body    = $body;
  $Mail-&gt;AltBody = $MessageTEXT;
  $Mail-&gt;Send();
  $Mail-&gt;SmtpClose();
  
  if(!$Mail-&gt;Send()) {
      $error = 'Mail error: '.$Mail-&gt;ErrorInfo; 
      echo($error);
      return false;
  } else {
      $error = 'Message sent!';
      return true;
  }
  </code></pre>