Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Failed to authenticate on SMTP server with username

Am trying to send email by Laravel. But It's getting error.

.env file Configuration below :

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

Controller Code Below :

 $data = array('name'=>"Ripon Uddin", "body" => "Test mail");

    Mail::send('email', $data, function($message) {
        $message->to('[email protected]','To My Yahoo')->subject('Laravel Test Email');
        $message->from('[email protected]','Ripon Uddin (Laravel Lover)');
    });

Error gettings :

Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials r18-v6sm7406256pgv.17 - gsmtp " in

like image 280
Ripon Uddin Avatar asked Oct 05 '18 21:10

Ripon Uddin


2 Answers

you don't need to have GSuite to do this... I have done this integration alot of times with Laravel & GMail. Just go to your Google Account > Security > Less secure app access and Click on "Turn on access (not recommneded)"See image for more info

like image 84
Haykins Avatar answered Oct 04 '22 03:10

Haykins


Go to this link or app password page of gmail then select 'mail' as "app" and custome name as "device". Then you will get app password. Just go to your laravel mai.php under config folder in production or env file in dev mode. Paste the generated code on password section 'password' => 'generated code', After all run: php artisan config:cache

like image 28
Nur Uddin Avatar answered Oct 04 '22 03:10

Nur Uddin