Trying to get Laravel 5 email to work Trying to get Laravel 5 email to work laravel laravel

Trying to get Laravel 5 email to work


I know it's working for you now @Vantheman6 but this is what worked for me in case it's the same for someone else.

I added to my .env file the details of the mail service I am using. So make sure the following details

MAIL_DRIVER=smtpMAIL_HOST=smtp.gmail.comMAIL_PORT=587MAIL_USERNAME=MyUsername@gmail.comMAIL_PASSWORD=MyPassword

in the .env file are accurate.

NOTE: Don't forget to restart your server after editing the .env file so it will pick the new data that you put in there.

Clear config cache with below command:

php artisan config:cache

If you don't restart your server, the .env file will still continue to present the old mail data to the app even though you have made changes that can cause this error.


My .env file configuration is like this for laravel 5.1

MAIL_DRIVER=smtpMAIL_HOST=smtp.gmail.comMAIL_PORT=587MAIL_USERNAME=example@gmail.comMAIL_PASSWORD=****************MAIL_ENCRYPTION=tls

here most important thing is that I created gmail application specific password(16 digit).

I need to reveal one more thing since no luck for any of configuration. That is, whenever I changed .env file need to run this command

php artisan config:cache

And this is most most most important because without this command laravel executes previous settings from it's cache. It's required me more than 10 hours to figure out.


You are getting an authentication error because the username and password in your config file is setup wrong.

Change this:

'username' => env('MyUsername@gmail.com'),'password' => env('MyPassword'),

To this:

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

The env method checks your .env file. In your .env file you call these MAIL_USERNAME, so that's what you need to pass to the env method.

One troubleshooting tip: add dd(Config::get('mail')); so that you can see the actual generated config. This will help you spot issues like this, and know exactly what information Laravel is going to try and use. So you may want to stop that in your test route temporarily to examine what you have:

Route::get('test', function(){    dd(Config::get('mail'));});