I’m working on my Laravel application and trying to get email functionality working. I followed a tutorial to set up Gmail SMTP but keep running into authentication issues.
Here’s my mail configuration:
'transport' => env('MAIL_MAILER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '[email protected]', 'name' => 'Sarah Developer'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => '[email protected]',
'password' => 'mypassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
And my .env file:
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
When I try to send an email, I get this error:
Swift_TransportException: Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators
I already enabled “Less secure app access” in my Gmail settings but still getting the same error. The Laravel logs show the SwiftMailer authentication handler is failing. Any ideas what might be causing this problem?
Gmail’s security changes are probably causing your authentication failure. You mentioned enabling “Less secure app access,” but if you’ve got 2FA turned on, that setting gets overridden. I hit this exact problem last year on a client project. Switch to App Passwords instead of your regular password - that’s what fixed it for me. Go to your Google Account security settings and generate an app password specifically for Laravel. You’ll get a unique 16-character password that skips the normal authentication. Also check that your .env variables are actually being read. I’ve seen config caching mess this up where old values stick around even after you update the .env file. Run php artisan config:clear after making changes so Laravel grabs the new credentials.
Google removed the “Less secure app access” feature in May 2022, which means it’s no longer a viable solution for SMTP authentication issues. Instead, you should generate an App Password to use with your Laravel setup. To do this, make sure you have 2-Step Verification enabled on your Google Account. Then, navigate to the Security section to generate an App Password specifically for your Laravel application. Replace the regular Gmail password in your .env file with this newly generated 16-character password. Additionally, confirm that your mail configuration is correctly pulling values from the .env file by using env() functions rather than hard-coding any credentials.
Check if your Laravel config is actually using the env variables. You’ve got hardcoded credentials in the mail config AND the env file - pick one. Also try port 465 with SSL instead of 587/TLS. Works better with Gmail in my experience.