title: PHPMailer fails to connect to google smtp server under debian
body: <p>I am trying to send an e-mail with PHPMailer. Here is my function to send an e-mail. It is working fine on localhost from an Ubuntu 14.04.</p>
  
  <pre><code>function smtpMail($to, $from, $from_name, $subject, $body) {
     $mail = new PHPMailer;
     $mail-&gt;IsSMTP();                                      // tells PHPMailer to use SMTP
     $mail-&gt;Host       = gethostbyname('smtp.gmail.com');  // sets the hostname of the mail server
     $mail-&gt;Port       = 587;                              // sets the SMTP port number
     $mail-&gt;SMTPSecure = 'tls';                            // sets the encryption system to use
     $mail-&gt;SMTPDebug  = 2;                                   // debug level
     $mail-&gt;SMTPAuth   = true;                             // whether to use SMTP authentication
     $mail-&gt;Username   = 'jdoe@company.org';            // username to use for SMTP authentication
     $mail-&gt;Password   = 'qwerty';                     // password to use for SMTP authentication
     $mail-&gt;CharSet    = 'UTF-8';
     $mail-&gt;IsHTML(true);
     $mail-&gt;setFrom($from, $from_name);                    // sets who the message is to be sent from
     $mail-&gt;Subject = $subject;
     $mail-&gt;Body = $body;
     $mail-&gt;AddAddress($to);
     if (!$mail-&gt;Send ()) {
             return 'Mail error: ' . $mail-&gt;ErrorInfo;
             //return 'KO';
     }
     return 'OK';
  }
  </code></pre>
  
  <p>Now I am trying to deploy it on a server. The code is the same but it is not working anymore. The server is an apache2 running inside a debian 8.2.
  PHPMailer prints these lines.</p>
  
  <pre><code>2015-12-09 13:35:41 SERVER -&gt; CLIENT: 220 2.0.0 Ready to start TLS
  2015-12-09 13:35:41 SMTP Error: Could not connect to SMTP host.
  2015-12-09 13:35:41 CLIENT -&gt; SERVER: QUIT
  2015-12-09 13:35:41 SERVER -&gt; CLIENT:
  2015-12-09 13:35:41 SMTP ERROR: QUIT command failed:
  </code></pre>
  
  <p>From the server the following commands are working fine :</p>
  
  <pre><code>dig smtp.gmail.com
  ping smtp.gmail.com
  telnet smtp.gmail.com
  </code></pre>
  
  <p>I tried to send an e-mail with telnet and it is also working. I followed this <a href="http://furie.be/news/38/15/Tester-le-SMTP-de-Gmail-via-Telnet.html" rel="nofollow">tutorial</a> (sorry it's in french)
  What am I doing wrong?</p>