Laravel 无法使用 gmail 发送电子邮件

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

早上好,以上是我在laravel 5.2尝试发送邮件时出现的错误,我之前尝试用mailtrap检查是否是代码,但运行顺利,所以我怀疑问题是 laravel .env 中的配置或邮件提供商端的配置(在本例中为 gmail),所以如果你能帮助我完成这项工作,我将非常感激

这是我的环境文件

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=my-account@gmail.com
MAIL_PASSWORD=my-password
MAIL_ENCRYPTION=tls

P.D.: 在 gmail

中激活了不太安全的应用程序

您发布的错误消息表明:

  1. Google 成功并正确接收了您发送电子邮件的尝试。
  2. Google 认为无论出于何种原因,您提供的凭据都是不可接受的。

根据错误信息中的URL,Google有一些提示:

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.

特别是,两步干扰或验证码可能是开始弄清楚为什么 Google 不开心的好地方。没有人喜欢不开心 Google.