Viewed   152 times

I recently encountered a SwiftMail error while trying to send a mail through gmail.

 Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted.

I was trying to send mail through my gmail and google thought that I was a spam(maybe because I was requesting too fast) I received a mail from them saying my account was access and I told them it was me. I was able to send mail without problem and it just occured now.

This is the contents of my env file.




I researched on the internet and some answers includes enabling the "access for lesser app" and "unlocking gmail captcha" which sadly didn't work for me until I found the 2-step verification.

What I did the following was:

  1. enable the 2-step verification to google HERE

  2. Create App Password to be use by your system HERE

  3. I selected Others (custom name) and clicked generate

  4. Went to my env file in laravel and edited this


  5. Restarted my apache server and boom! It works again.

This was my solution. I created this to atleast make other people not go wasting their time researching for a possible answer.

Thursday, September 22, 2022

your mail.php on config you declare host as and port is 587 while on env is different. you need to change your mail.php to

'host' => env('MAIL_HOST', ''),
'port' => env('MAIL_PORT', 2525),

if you desire to use mailtrap.Then run

php artisan config:cache
Sunday, August 7, 2022

Update my driver line to


It works on the first try.

Final .env file should look like this

Friday, October 28, 2022

Swiftmailer 6.0 does not support the mail driver anymore

With laravel, you also updated swiftmailer, and thus, the mail driver does not work anymore.

Here is the swiftmailer commit that removed the mail driver in 6.0.

It was deprecated since Swiftmailer 5.4.5 with this commit.

Here is a long discussion about why it was removed, where the most useful comment says that:

PHP's mail() function is insecure

The fifth parameter can be exploited to execute arbitrary code on most Linux systems. This is mainly because PHP incorrectly escapes shell arguments. You can read the full explanation in "Why mail() is dangerous in PHP" by RIPS.

A couple of applications had security issues because of that, including Roundcube webmailer, MediaWiki, PHPMailer, ZendFramework, SquirrelMail and Swiftmailer. And your app. So be thankful that it got removed and use SMTP instead. You can usually simply use your local mail server using:


(You may need to use tls encryption if your server does not accept local unencrypted mail.)


The main issue with Laravel is that its documentation still mentions the mail driver in the Laravel 5.7 documentation and did only mention in their upgrade notes for 5.5 that swiftmailer 6.0 is required, but not that this means you cannot use the mail driver anymore.

Monday, October 3, 2022
  1. if you are using gmail address to sent mail. then you need to on less secure app.

    go to

    then allow by turning it on.

    and also use php artisan config:clear

  2. sometimes google blocks when you try to send email through some code. In that case you got a alert mail. click on that mail(Check Activity) and mark as yes (Do you recognize this activity?)

  3. Or you can try MAIL_DRIVER=sendmail and also use php artisan config:clear

Friday, October 14, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :