title: Laravel : Swift_TransportException Connection could not be established with host smtp.gmail.com
body: <p>I am trying to send email in <code>Laravel</code> using <code>Swift Mailer</code>, i have been trying from last 3 days but <code>No Luck</code>.<br /></p>
  
  <p>I have Godaddy Shared hosting, i already discussed with <code>Customer Support</code> , they said there is no issue from there side</p>
  
  <p>I am not able to find what is wrong in this code.</p>
  
  <p>Already Referred this post but didn't get any solutions.</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/27721120/laravel-connection-could-not-be-established-with-host-smtp-gmail-com-0">Laravel - Connection could not be established with host smtp.gmail.com [ #0]</a><br /></li>
  <li><a href="https://stackoverflow.com/questions/14176965/swift-transportexception-connection-could-not-be-established-with-host-smtp-gmai">Swift_TransportException Connection could not be established with host smtp.gmail.com</a> <br /></li>
  <li><a href="https://stackoverflow.com/questions/41177580/connection-could-not-be-established-with-host-smtp-gmail-com-connection-timed-o">Connection could not be established with host smtp.gmail.com [Connection timed out #110] in laravel 5.2</a></li>
  <li><a href="https://stackoverflow.com/questions/41425107/how-to-resolve-the-error-message-fsockopen-unable-to-connect-to-ssl-smtp">How to resolve the error: Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)</a></li>
  </ol>
  
  <blockquote>
    <p>Code</p>
  </blockquote>
  
  <pre><code>   $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
        -&gt;setUsername('my@gmail.com')
        -&gt;setPassword('*****');
  
        $nam = 'abc';
        $from = 'my@gmail.com';
  
        $message = \Swift_Message::newInstance($subject)
  
        -&gt;setFrom(array($from =&gt; $name))
        -&gt;setTo(array($to))
        -&gt;setBody($body);
        $message-&gt;setContentType("text/html");
        $mailer = \Swift_Mailer::newInstance($transport);
        $result = $mailer-&gt;send($message);
          return $result;
  
  
  
  Please ignore Variable declaration, like $subject and ect....
  </code></pre>
  
  <p>Port Tried.</p>
  
  <pre><code>1. 465
  2. 587
  3. 80
  4. 25
  5. 110 ( Gmail Commercial Email )
  </code></pre>
  
  <p>It's showing error</p>
  
  <blockquote>
    <p>Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465
    (Connection refused)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/uayLy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uayLy.png" alt="enter image description here"></a></p>