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

5/5 - (1 vote)

I’m trying to send an email from Gmail using Laravel from the localhost (I use XAMPP for Windows).

Set your .env file

Open you’re .env which is located in your root directory of our application and checkout for this settings:

#MAIL_DRIVER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=My_EMAIl_ADDRESS
MAIL_PASSWORD=MY_EMAIL_PASSWORD
MAIL_ENCRYPTION=ssl

Configure your Google Account

Open Your Google account and give access to less secured applications.
Login to your Google Email Account, go click on Google Account Button, then click on Security, go to Less secure app access settings and turn the radio button to ON.

In my case, Not working with these settings! I’m getting this error:

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

Solution

In the 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.

Hello there!

I hope you find this post useful!

I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

subscribe youtube

Leave a Comment

WebPedia.net