Connection could not be established with host smtp

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

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

Watching: Connection could not be established with host smtp

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.


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

“stream” => true, “verify_peer” => false, “verify_peer_name” => false, >, >It worked for me.

Fyi, my SMTP settings are:

I had the same error: Connection could not be established with host and followed the steps outlined here:

Try adding the following lines to _establishSocketConnection() in Swift/Transport/StreamBuffer.php on line 263:

$options = FALSE;$options = FALSE;Note that this is not a perfect solution as it involves: a) Hacking core code which may be overwritten in a SwiftMailer update, and b) decreases the security of your app as you”re no longer validating the connection. But as a temporary work-around it worked for me.


This one line change in .env file will make it work

MAIL_DRIVER=sendmailIf it also has no effect try to switch between the mail port


MAIL_PORT=465This will work only if you enable “Allow Less secure app access” under google account


In your .env file you will need to set the email address and password of your email account:

See Also:  How do i create stationery in gmail?
gmail.comMAIL_PASSWORD=testpasswordand in mail.php

env(“MAIL_DRIVER”, “smtp”), “host” => env(“MAIL_HOST”, “”), “port” => env(“MAIL_PORT”, 587), “from” => “yourEmail”, “name” => “Your Title”>, “encryption” => “tls”, “username” => env(“MAIL_USERNAME”), “password” => env(“MAIL_PASSWORD”), “sendmail” => “/usr/sbin/sendmail -bs”, “pretend” => false,>;and clear the config cache with:

php artisan config:cache
here”s what is working with me you are two auth verification with your account , should be generate new app password and use into you env file. this is what working with me.

Have you tried changing the encryption to tls? I currently use a Gmail SMTP sever to send emails from my Laravel app. I use TLS and port 587
in localhost you can set your MAIL_DRIVER=smtp but on real server like cpanel you must to set MAIL_DRIVER=sendmail and edit your config/mail.php”default” => env(“MAIL_MAILER”, “sendmail”),but its not good idea because after you send mail on google you get error on gmail like this :

Be careful with this messageGmail could not verify that it actually came from tenetup.reminderme
For me, it turned out TripMode blocked nginx & php-fpm. So make sure no app like this or firewall is blocking the connection to the mail server.

Readmore: How To Enable Quickbooks To Send Emails With Avast Antivirus? ?

If you are using Amazon EC2, do ensure to set outbound rules for SMTP (25) and SMTPS (465) to Anywhere.

See Also:  General 20+ how to remove phone number from yahoo mail best, don't miss

On Cpanel changing only the MAIL_DRIVER to sendmail from smtp in .env works for me.

this worked for me after a long search time, the best configuration :

“driver” => “smtp”,”host” => “”,”port” => 587, ( or 25)”encryption” => “tls”,
You can”t send emails from your localhost by default.

If you configure your files correctly, you would be able to send emails from it.

Readmore: Powerbot For Gmail Plugin For Chrome, Powerbot For Gmail Now Works With

You could also try to upload the site on an server or production zone. There it will work.

Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Not the answer you’re looking for? Browse other questions tagged laravel-4 gmail or ask your own question.

In remote host: Connection could not be established with host
Using gmail smtp via Laravel: Connection could not be established with host

Categories: Mail

Leave a Reply

Your email address will not be published.