Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Connection could not be established with host smtp.gmail.com [ #0]

I'm trying to send an email from Gmail using Laravel from localhost. I'm getting this error: Connection could not be established with host smtp.gmail.com [ #0]

I'm using ssl with port 465. I also tried 587 but it didn't work.

I also tried this but it didn't work. I found a lot of people suffering from the same problems, but the solutions I found didn't work.

like image 757
omarsafwany Avatar asked Dec 31 '14 12:12

omarsafwany


1 Answers

Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.

Be sure you fully understand the security issues before using this as a solution.

In Laravel project directory, edit config/mail.php and add the following:

'stream' => [         'ssl' => [             'allow_self_signed' => true,             'verify_peer' => false,             'verify_peer_name' => false,         ],     ] 

It worked for me.

Fyi, my SMTP settings are:

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME=[Full Gmail Address] MAIL_PASSWORD=[Google App Password obtained after two step verification on Google Account Page] MAIL_ENCRYPTION=ssl 
like image 124
Ahmed Numaan Avatar answered Sep 21 '22 16:09

Ahmed Numaan