Search code examples
phplaravelgmailemail

Laravel not working sending emails with gmail


Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/answer/14257 x201sm24123472qkx.32 - gsmtp

Good morning, above is the error I get in laravel 5.2, trying to send an email, I tried before with mailtrap to check if it was the code, but it worked smoothly, so I suspect that the issue is or the config in laravel .env or the configuration on the mail provider end (in this case gmail), so if you can help me to make this works, I would be very grateful

This is my env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=my-password
MAIL_ENCRYPTION=tls

P.D.: less secure app is activated in gmail


Solution

  • The error message you posted indicates that:

    1. 👍 Your attempt to send an email is being received successfully and correctly by Google.
    2. 👎 Google believes that the credentials you supplied are unacceptable, for whatever reason.

    Following the URL in the error message, Google has some tips:

    If you’re sure your password is right, try these tips:

    • If you've turned on 2-Step Verification for your account, you might need to enter an App password instead of your regular password.
    • Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.
    • Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your account.
    • Change your password according to our tips on creating a strong password.

    In particular, 2-Step interference or the captcha might be good places to start figuring out why Google is unhappy. Nobody likes an unhappy Google.