title: PHPMailer not working in my server
body: <p>I built a droplet with Ubuntu with DigitalOcean and I'm trying to configure it to send emails with SMTP.</p>
  <p>I know DigitalOcean blocks SMTP over IPv6 but not over IPv4 so I disabled IPv6 as <a href="https://askubuntu.com/questions/440649/how-to-disable-ipv6-in-ubuntu-14-04">this post says</a>.</p>
  <p>My script still doesn't work. I've tried with ports 25, 465 and 587. TLS and SSL.</p>
  <p>I've installed <code>sendmail</code> for Ubuntu 14.04 but not working.</p>
  <p>This is my script:</p>
  <pre><code>&lt;?php
      require 'mail/PHPMailerAutoload.php';
      
      $mail = new PHPMailer;
      
      $to = $_GET['email'];
      
      $mail-&gt;isSMTP();
      $mail-&gt;Host = 'smtp.gmail.com';
      $mail-&gt;SMTPAuth = true;
      $mail-&gt;Username = 'rafawins@gmail.com';
      $mail-&gt;Password = '***';
      $mail-&gt;SMTPSecure = 'tls';
      $mail-&gt;Port = 587;
      
      $mail-&gt;setFrom('rafawins@gmail.com', 'Rafael');
      
      $mail-&gt;addAddress($to);
      
      $mail-&gt;isHTML(true);
      
      $mail-&gt;Subject = 'Subject';
      $contents = ob_get_contents();
      $mail-&gt;Body    = &quot;ao!&quot;;
      
      if(!$mail-&gt;send()) {
          echo 'Message could not be sent.';
          echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
      } else {
          echo 'Message has been sent';
      }
      print_r(error_get_last());
      
  
  ?&gt;
  </code></pre>
  <p>The error presented is:</p>
  <blockquote>
  <p>SMTP connect() failed.</p>
  </blockquote>
  <p>I'm interested in sending email <strong>using SMTP</strong> so <code>-&gt;isSMTP()</code> is required!</p>
  <p>Where am I wrong?</p>
  <p>Thank you very much.</p>
  <hr />
  <p><strong>EDIT:</strong></p>
  <p>doing: <code>telnet smtp.gmail.com 587</code>
  I get:</p>
  <blockquote>
  <p>Trying 74.125.133.108...</p>
  <p>Connected to gmail-smtp-msa.l.google.com.</p>
  <p>Escape character is '^]'.</p>
  <p>220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp</p>
  </blockquote>
  <p>and doing: <code>openssl s_client -connect smtp.gmail.com:465</code> I get an answer as well...</p>
  <p>What's wrong?</p>