Skip to content
Fix Code Error

Failed to authenticate on SMTP server error using gmail

March 15, 2021 by Code Error
Posted By: Anonymous

I’m trying to set up email for my first laravel project, and was thrilled that there’s a laracast for it: https://laracasts.com/lessons/mailers

I’ve followed the simple steps, chose gmail in mail.php (x’s added for anonymity):

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'diane✘✘✘[email protected]', 'name' => 'Diane Kaplan'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => 'diane✘✘✘[email protected]',
'password' => '✘✘✘xx',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

.env has (x’s added for anonymity)- the laracast doesn’t have us use MAIL_USERNAME and MAIL_PASSWORD, but they’re updated for good measure assuming I’ll pull from there later:

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=diane✘✘✘[email protected]
MAIL_PASSWORD=✘✘✘✘✘✘
MAIL_ENCRYPTION=null

But in the first little moment of truth trying to send a mail (3:30 mark), I get an authentication error:
Swift_TransportException in AuthHandler.php line 181:
Failed to authenticate on SMTP server with username “diane✘✘✘[email protected]” using 3 possible authenticators

Based on a little stackoverflow reading, I tried turning on ‘access to less secure apps’ in my gmail settings, but no change in the error. (And the other posts about this issue had other factors that made a fancier problem than mine).

Nothing jumps out at me from laravel.log (below)- any ideas?

[2015-11-26 12:25:55] local.ERROR: exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators' in /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:181
Stack trace:
    #0 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
    #1 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(118): Swift_Transport_EsmtpTransport->_doHeloCommand()
    #2 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
    #3 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(395): Swift_Mailer->send(Object(Swift_Message), Array)
    #4 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(181): IlluminateMailMailer->sendSwiftMessage(Object(Swift_Message))
    #5 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(220): IlluminateMailMailer->send('emails.welcome', Array, Object(Closure))
    #6 /home/vagrant/Code/Family-laravel/app/Http/routes.php(59): IlluminateSupportFacadesFacade::__callStatic('send', Array)
    #7 /home/vagrant/Code/Family-laravel/app/Http/routes.php(59): IlluminateSupportFacadesMail::send('emails.welcome', Array, Object(Closure))
    #8 [internal function]: AppProvidersRouteServiceProvider->{closure}()
    #9 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(155): call_user_func_array(Object(Closure), Array)
    #10 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(130): IlluminateRoutingRoute->runCallable(Object(IlluminateHttpRequest))
    #11 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(704): IlluminateRoutingRoute->run(Object(IlluminateHttpRequest))
    #12 [internal function]: IlluminateRoutingRouter->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
    #13 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
    #14 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #15 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
    #16 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(706): IlluminatePipelinePipeline->then(Object(Closure))
    #17 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(671): IlluminateRoutingRouter->runRouteWithinStack(Object(IlluminateRoutingRoute), Object(IlluminateHttpRequest))
    #18 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(631): IlluminateRoutingRouter->dispatchToRoute(Object(IlluminateHttpRequest))
    #19 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): IlluminateRoutingRouter->dispatch(Object(IlluminateHttpRequest))
    #20 [internal function]: IlluminateFoundationHttpKernel->IlluminateFoundationHttp{closure}(Object(IlluminateHttpRequest))
    #21 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
    #22 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(50): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #23 [internal function]: IlluminateFoundationHttpMiddlewareVerifyCsrfToken->handle(Object(IlluminateHttpRequest), Object(Closure))
    #24 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #25 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #26 [internal function]: IlluminateViewMiddlewareShareErrorsFromSession->handle(Object(IlluminateHttpRequest), Object(Closure))
    #27 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #28 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #29 [internal function]: IlluminateSessionMiddlewareStartSession->handle(Object(IlluminateHttpRequest), Object(Closure))
    #30 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #31 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #32 [internal function]: IlluminateCookieMiddlewareAddQueuedCookiesToResponse->handle(Object(IlluminateHttpRequest), Object(Closure))
    #33 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #34 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #35 [internal function]: IlluminateCookieMiddlewareEncryptCookies->handle(Object(IlluminateHttpRequest), Object(Closure))
    #36 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #37 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #38 [internal function]: IlluminateFoundationHttpMiddlewareCheckForMaintenanceMode->handle(Object(IlluminateHttpRequest), Object(Closure))
    #39 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #40 [internal function]: IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
    #41 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(IlluminateHttpRequest))
    #42 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): IlluminatePipelinePipeline->then(Object(Closure))
    #43 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): IlluminateFoundationHttpKernel->sendRequestThroughRouter(Object(IlluminateHttpRequest))
    #44 /home/vagrant/Code/Family-laravel/public/index.php(54): IlluminateFoundationHttpKernel->handle(Object(IlluminateHttpRequest))
    #45 {main}  

Solution

Did you turn on the “Allow less secure apps” on? go to this link

https://myaccount.google.com/security#connectedapps

Take a look at the Sign-in & security -> Apps with account access menu.

You must turn the option “Allow less secure apps” ON.

If is still doesn’t work try one of these:

  • Go to https://accounts.google.com/UnlockCaptcha , and click continue
    and unlock your account for access through other media/sites.

  • Use double quote in your password: “your password”

And change your .env file

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

because the one’s you have specified in the mail.php will only be used if the value is not available in the .env file.

Answered By: Anonymous

Related Articles

  • Expected response code 220 but got code "", with message ""…
  • Trying to get Laravel 5 email to work
  • Unable to send email using Gmail SMTP server through…
  • Avoid creating new session on each axios request laravel
  • PEAR Mail in php:apache Docker container
  • How to resolve javax.mail.AuthenticationFailedException…
  • Could not connect to SMTP host - failed to verify…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Mail not sending with PHPMailer over SSL using SMTP
  • Reference — What does this symbol mean in PHP?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to transform array to comma separated words string?

Next Post:

What is the best practice for creating a favicon on a web site?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error