editor@linuxhint.com

How to send an email using Gmail with Laravel

Problem

I am trying to connect my Gmail account with my Laravel application, however, I am not getting much progress. I keep getting the authentication issues:

Expected response code 250 but got code 530 with message 530 5.7.1 Authentication required

Solution

First you need to make sure that your Gmail is ready to be used with your Laravel application. Head over to your Gmail account and under My account > Sign In And Security > Sign In to google, enable two step verification. After that, you can generate an app password, and you can use that app password in your .env file.

Your .env file will then look something like this

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=newapppassword
MAIL_ENCRYPTION=tls

Don’t forget to run php artisan config:cache after you make changes in your .env file.