Using gmail smtp via Laravel: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
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,
Related videos on Youtube
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, 2021Comments
-
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.
-
Fefar Ravi over 2 yearsI hope this tutorial is help: The connection could not be established with host smtp.gmail.com
-
-
Ahmad over 9 yearsAnd you used smtp of gmail? then I think the driver should be smtp, not?
-
code-8 over 8 yearsThis proceed through, but the email is not sending.
-
mr5 over 8 yearsWhere could I find those configurations?
-
Aryeh Armon about 8 years@mr5 config/email.php
-
John Roca almost 8 yearsWhy did you use 'sendmail' not 'smtp'? What is the difference of "sendmail" and "smtp". Please provide explanation.
-
Jaykesh Patel over 7 yearsSendmail driver option send email through server default smtp. It is not send mail through google smtp.. this is not true answer.
-
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 over 7 yearsWhere is vi/etc/gai..?
-
Nur Uddin almost 7 yearsit works for me! replaced ` 'driver' => env('MAIL_DRIVER', 'smtp'),` with ` 'driver' => 'sendmail',` in config/mail.php
-
moses toh over 6 years@李偉成, Where I can set it? Maybe you can help me. Look at this : stackoverflow.com/questions/48654849/…
-
moses toh over 6 yearsWhere I can set it? Maybe you can help me. Look at this : stackoverflow.com/questions/48654849/…
-
Vishal B over 5 yearsdid send mail??
-
Mr Coder about 4 yearssendmail is lib for linux system first need to activate on server side then it will works
-
Mr Coder about 4 yearssendmail 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