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

PhpLaravelGmail

Php Problem Overview


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.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME[email protected]
MAIL_PASSWORD=mypasswordhere
MAIL_FROM[email protected]
MAIL_NAME=talentscout

Php Solutions


Solution 1 - Php

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

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

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

    MAIL_USERNAME=[email protected]

    MAIL_PASSWORD=thepasswordgenerated

  3. 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.

Solution 2 - Php

I had the same problem, changing my gmail password fixed the issue, and also don't forget to enable less secure app on on your gmail account

Solution 3 - Php

i had same issue i resolve this use under

go to gmail.com

my account

and enable

Allow less secure apps: ON

it start works

Solution 4 - Php

I had everything fine. Less secure app option was also enabled. Still, I was getting the error. What I have done is:

  • Google will send you Critical security alert
  • Then you have to authorize that activity. ( Clicking on 'YES, THAT WAS ME' type thing )
  • Then you can try sending email again.

Solution 5 - Php

This single step worked for me... No 2-step verification. As I had created a dummy account for my local development, so I was OK with this setting. Make sure you only do this if your account contains NO personal or any critical data. This is just another way of tackling this error and NOT secure.

I turned ON the setting to alow less secured apps to be allowed access. Form here : https://myaccount.google.com/lesssecureapps

Solution 6 - Php

This is my .env mail settings

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=587
MAIL_USERNAME[email protected]
MAIL_PASSWORD=hello27
MAIL_ENCRYPTION=tls

i was getting thesame error as stated in the question but by using

php artisan config:cache

Everything worked fine

Solution 7 - Php

Gmail tends to block usage of mailing addresses which are being used in other applications as username for security reasons. Either you should create a new email address for mail purpose or you must go to the Less Secure App Access and turn on the access for less secure apps. Gmail will send you a mail for confirmation from where you can verify that those changes were made by yourself. Only then, you can use such mailing addresses for mailing purpose through applications.

Solution 8 - Php

There is no need to update anything in config/mail.php. just put you credential in .env with this specific key's. This is my .env file.

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

I had the same issue after long time debugging and googling i have found the solution. that by enabling less secure apps. the email started working.

if your gmail is secure with 2 step verification you can't enable less secure app. so turn off 2 step verification and enable less secure app. by click here enable less secure apps on your gmail account

Solution 9 - Php

I had the same problem, then I did this two steps:

  • Enable "Allow less secure apps" on your google account security policy.
  • Restart your local servers.

Solution 10 - Php

I encountered the same issue and solved it with no 2FA enabled ("Allow less secure apps" is still in need).

After checking Google error code list, I thought maybe there are some errors in .env.

Below settings are tested in Laravel 8 and worked:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME[email protected]
MAIL_PASSWORD='your#password_here'  # put the password in quotes
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS[email protected]
MAIL_FROM_NAME="${APP_NAME}"

Please remember that put the password in quotes. That works for me.

Solution 11 - Php

I had this issue. first checked the credentials and username, they were all good, then restarted my server (docker stop/start) and it works now. something with cache I believe

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCamilo Go Jr.View Question on Stackoverflow
Solution 1 - PhpCamilo Go Jr.View Answer on Stackoverflow
Solution 2 - PhpM-O-H-S-E-NView Answer on Stackoverflow
Solution 3 - PhpTigranView Answer on Stackoverflow
Solution 4 - PhpMasiur Rahman SiddikiView Answer on Stackoverflow
Solution 5 - PhpcosmolocView Answer on Stackoverflow
Solution 6 - Phpovie tennysonView Answer on Stackoverflow
Solution 7 - PhpJiwanView Answer on Stackoverflow
Solution 8 - PhpsachinsuthariyaView Answer on Stackoverflow
Solution 9 - PhpDaniel BeltramiView Answer on Stackoverflow
Solution 10 - Phphms5232View Answer on Stackoverflow
Solution 11 - PhpAhmad MousaviView Answer on Stackoverflow