user194324
user194324

Reputation: 38

Laravel 6 send mail

I have an issue with authentication while sending mail with Laravel smtp driver.

.env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
[email protected]
MAIL_PASSWORD=app_password
MAIL_ENCRYPTION=tls

It gives the following error:

"530-5.7.0 Authentication Required. "

SO all typical solutions are not working. What else may cause this problem?

I have also tried using smtp.vivaldi.net with vivaldi account, it authenticates, but gives an error:

"no valid recipients"

while recipient email is surely valid, which is also strange for me.

Upvotes: 0

Views: 570

Answers (3)

user194324
user194324

Reputation: 38

Problem was that I messed up with config/mail.php.

I wrote

'username' => env('email'), 'password' => env('app_password'),

Instead of

'username' => env('MAIL_USERNAME','email'), 'password' => env('MAIL_PASSWORD','app_password'),

Upvotes: 0

Christoph
Christoph

Reputation: 2007

I've stumbled across this multiple times already, hence I do not remember the exact error-message which I received but here is my assumption.

Google has an option called "less secure apps" which you need to enable in order to send directly mails through their SMTP interface. Can you check if this flag is disabled and try to enable it?

https://support.google.com/a/answer/6260879

In addition to that google is slowly deprecating this feature. Starting from Mid 2020 you'll be not able to enable this flag anymore and they will completely remove this in 2021.

Reference: https://gsuiteupdates.googleblog.com/2019/12/less-secure-apps-oauth-google-username-password-incorrect.html

Upvotes: 2

STA
STA

Reputation: 34678

Firstly, you need to setup 2 step verification here google security. An App Password link will appear and you can get your App Password to insert into below "MAIL_PASSWORD". More info on getting App Password here

MAIL_DRIVER=smtp
[email protected]
MAIL_FROM_NAME=System
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=YOUR_GMAIL_CREATED_APP_PASSWORD
MAIL_ENCRYPTION=tls

Don't forget to clear cache with :

php artisan config:cache

Upvotes: 0

Related Questions