Using gmail smtp via Laravel: Connection could not be established with host smtp.gmail.com [Connection timed out #110]

123,091

Solution 1

I had the same problem and I resolved it in this way:

'driver' => 'sendmail',

You need to change only that line.

Solution 2

After doing lot of research I found this one helpful.

https://www.google.com/settings/security/lesssecureapps.

Open the above link .

Click on Enable. And save it.

Then try to send email again.

For me it worked .

Solution 3

Solved mine by changing my .env file as follows:

'driver' => 'sendmail',

Solution 4

Works for me with same settings except encryption and port. Change to:

'encryption' => ssl,
'port' => 465,

Since this is only for localhost encryption line should also be environment specific. So instead above I did following:

env('MAIL_ENCRYPTION','tls'),

Now you can set this in .env file, which is environment specific and should be in .gitignore

Solution 5

Try

'encryption' => 'ssl',

'port' => 465,
Share:
123,091

Related videos on Youtube

Ahmad
Author by

Ahmad

I am a university instructor teaching computer courses, I am also a researcher, programmer, web designer and application developer I mainly work with C# .Net, PHP Mysql.

Updated on May 24, 2021

Comments

  • Ahmad
    Ahmad almost 3 years

    When I try to use GMail SMTP for sending email via Laravel, I encounter the following error:

    Swift_TransportException
    
    Connection could not be established with host smtp.gmail.com [Connection timed out #110]
    

    It is the trace of the error:

    ...
     }
    $this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
    if (false === $this->_stream) {
    throw new Swift_TransportException(
    'Connection could not be established with host ' . $this->_params['host'] .
    ' [' . $errstr . ' #' . $errno . ']'...
    

    and here are my configuration for mail:

    'driver' => 'smtp',
    
    'host' => 'smtp.gmail.com',
    
    'port' => 587,
    
    'from' => array('address' => '[email protected]', 'name' => 'some'),
    
    'encryption' => 'tls',
    
    'username' => '[email protected]',
    
    'password' => 'mypassword',
    
    'sendmail' => '/usr/sbin/sendmail -bs',
    
    'pretend' => false
    

    I use a shared host and the port 587 on localhost is open.

  • Ahmad
    Ahmad over 9 years
    And you used smtp of gmail? then I think the driver should be smtp, not?
  • code-8
    code-8 over 8 years
    This proceed through, but the email is not sending.
  • mr5
    mr5 over 8 years
    Where could I find those configurations?
  • Aryeh Armon
    Aryeh Armon about 8 years
    @mr5 config/email.php
  • John Roca
    John Roca almost 8 years
    Why did you use 'sendmail' not 'smtp'? What is the difference of "sendmail" and "smtp". Please provide explanation.
  • Jaykesh Patel
    Jaykesh Patel over 7 years
    Sendmail driver option send email through server default smtp. It is not send mail through google smtp.. this is not true answer.
  • Chinmay235
    Chinmay235 over 7 years
    @mr5 You could find configuration in config/mail.php or .env file in the root directory(laravel 5.3).
  • Kenziiee Flavius
    Kenziiee Flavius over 7 years
    Where is vi/etc/gai..?
  • Nur Uddin
    Nur Uddin almost 7 years
    it works for me! replaced ` 'driver' => env('MAIL_DRIVER', 'smtp'),` with ` 'driver' => 'sendmail',` in config/mail.php
  • moses toh
    moses toh over 6 years
    @李偉成, Where I can set it? Maybe you can help me. Look at this : stackoverflow.com/questions/48654849/…
  • moses toh
    moses toh over 6 years
    Where I can set it? Maybe you can help me. Look at this : stackoverflow.com/questions/48654849/…
  • Vishal B
    Vishal B over 5 years
    did send mail??
  • Mr Coder
    Mr Coder about 4 years
    sendmail is lib for linux system first need to activate on server side then it will works
  • Mr Coder
    Mr Coder about 4 years
    sendmail is lib for linux system first need to activate on server side then it will works if you using a phpmailer you have option with what stmp service be useing. sendmail id lib for linux package it create stmp server on machine