I am trying to send mail for my laravel application from a gmail account using Allow less secure applications: ON and 2-Step Verification OFF
.env for mail:
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=library@gmail.com MAIL_PASSWORD=******** MAIL_ENCRYPTION=ssl
config / mail.php:
'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.gmail.com'), 'port' => env('MAIL_PORT', 587), 'from' => ['address' => ' library@gmail.com ', 'name' => 'Admin'], 'encryption' => env('MAIL_ENCRYPTION', 'ssl'), 'username' => env(' library@gmail.com '), 'password' => env('********'), 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => env('MAIL_PRETEND', false),
At first I tried to use 'encryption' => env('MAIL_ENCRYPTION','tls') . But the following error message appeared:
ERROR: exception 'Swift_TransportException' with message 'Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 z3sm16020712par.17 - gsmtp"' in /home/shafi/Projects/Lib/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
I visited https://support.google.com/mail/answer/14257 and found that everything is in recommended condition.
After that I used 'encryption' => env('MAIL_ENCRYPTION','ssl') , but this time the same ERROR .
What should I do to fix the error? What am I missing?