title: How to resolve: Connection could not be established with host smtp.gmail.com [Connection timed out #110] error in PHP
body: <p>I'm trying to set up an email verification system for a login system that I am working on. I've got mostly everything working in my php code, up until the $mailer->send($message) line which returns the above error.</p>
  
  <p>I've looked at several other similar issues on stackoverflow and other sites, but none of the proposed solutions have worked. I have less secure apps enabled on the gmail account that is sending the verification email. I've tried ssl and tls with ports 465 and 587 respectively. I don't wish to disable anything security related unnecessarily. While I am fairly confident in my coding knowledge, I'm afraid I have very little experience with server related issues like this. I've created a login system with email verification successfully in the past, but I don't remember how I avoided this issue. If this is related to firewalls or something like that, I only ask for a little more information as one can assume I'm essentially a layman in that area. </p>
  
  <pre><code>&lt;?php
  require_once './vendor/autoload.php';
  
  function sendVerificationEmail($userEmail, $verificationCode)
  {
  $transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
  -&gt;setUsername("fromEmail@email.com")
  -&gt;setPassword("password");
  
  $mailer = new Swift_Mailer($transport);
  $body = "";
      $message = (new Swift_Message('Verify your email'))
          -&gt;setFrom("fromEmail@email.com")
          -&gt;setTo($userEmail)
          -&gt;setBody($body);
  
      echo "Message Created. Send To: " . $userEmail;
      try
      {
        if ($mailer-&gt;send($message, $errors))
        {
          echo "email success.";
          return true;
        }
        else
        {
          echo "email no good.";
          echo "ERROR: " . $errors;
          return false;
        }
      }
      catch(Swift_SwiftException $e)
      {
        echo "ERROR: " . $e-&gt;getMessage();
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Much of this code is derived from the standard tutorials. I'm just trying to make sure an email is sent before I actually include the functionality for verification. I do not know why this is not sending an email. It's specifically returning the 'Connection could not be established with host smtp.gmail.com [Connection timed out #110]' error.</p>
  
  <p>Thank you for your time.</p>