Reputation: 18006
I know this question is asked many times and have different solutions and I have tried all but no one has worked. This is my settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
And application is currently running on Centos 7
OS.
I always get
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
I have tried all solutions, by Replacing: smtp.gmail.com with 173.194.65.108
, or replacing smtp.gmail.com by gmail-smtp-msa.l.google.com
. When I do these two steps, it got server not found error.
If I change mail driver from smtp to sendmail or mail
, no error is thrown but no email is sent.
If I use ip address of smtp.gmail.com, I got same result. If I change port from 465 to 587
and encryption from ssl to tls
, nothing happens.
I have also created a file in etc/gai.conf
and put precedence ::ffff:0:0/96 100
. It worked one time. But later after two hours, it stopped working and started throwing same error.
I have also tried using my gmail id but all in vain.
The only solution that I couldn't be able to test is verifying httpd_can_sendmail
as whenever I run command getsebool httpd_can_sendmail
I get getsebool: SELinux is disabled
. Is this the problem or is there any other way to get it fixed?
Upvotes: 3
Views: 4021
Reputation: 130
In my case it was necessary to clear config cache to pull up .env file new settings
php artisan config:cache
Upvotes: 1
Reputation: 28
Since you are using gmail, but I don't know what password you are setting, the MAIL_PASSWORD variable must be the same as the gmail application password. In this case, Gmail provides a third-party application service so that these, (in this case your application), can send emails using this type of authentication.
Upvotes: 0
Reputation: 164
Here is my working mail config file:
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => '*******@gmail.com', 'name' => '****'],
'encryption' => 'tls',
'username' => '*******@gmail.com',
'password' => '*******',
'sendmail' => '/usr/sbin/sendmail -bs',
];
but from your question i can see you already tried all this, so i can assume it is a network problem based on error 'connection time out', what i mean is that something is blocking your connection, it might be your firewall if you have.
so first you should check that the port 587 is open, or you can check if other application can connect with smtp.gmail.com (don't know how to do it in centOs).
And at last this might not be a problem but you have to enable 'Allow less secure apps' in your google account just for testing. (This is not permanent solution but for testing, if it works then you should enable two step verification in google account and then create new application, you can create new special password which you can use as your password for smtp server)
Upvotes: 1