Laravel Gmail无法使用,"用户名和密码不被接受.了解详情..."

use*_*533 19 php gmail laravel

当我尝试通过运行Laravel 4的网站发送电子邮件时,我遇到了以下异常:

{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Run Code Online (Sandbox Code Playgroud)

这是我的邮件配置:

return array(
  'driver' => 'smtp',
  'host' => 'smtp.gmail.com',
  'port' => 465,
  'from' => array('address' => 'mymail@gmail.com', 'name' => 'myname'),
  'encryption' => 'ssl',
  'username' => 'mymail@gmail.com',
  'password' => 'lol',
  'sendmail' => '/usr/sbin/sendmail -bs',
  'pretend' => false,
);
Run Code Online (Sandbox Code Playgroud)

我试过通过谷歌搜索这个问题找到的禁用链接,除了它没有什么区别.

有没有办法告诉谷歌"停止阻止这个IP,这是我"?

Pat*_*ros 46

我尝试了同样的事情并得到了同样的错误.所以我亲自检查了我的Gmail帐户,我收到了Gmail发来的消息让我知道他们已阻止对我的电子邮件帐户的访问尝试.

他们通过访问https://www.google.com/settings/security/lesssecureapps显示了禁用此安全设置的选项.


tha*_*c89 27

转到此链接并停用解锁验证码 https://accounts.google.com/b/0/DisplayUnlockCaptcha

  • @ trinity420这只是因为为了安全起见,谷歌默认阻止了对SMTP的不安全登录. (2认同)

dil*_*dil 14

试试这个:

  1. 将端口更改为587
  2. 转到gmail设置https://www.google.com/settings/security/lesssecureapps 并激活它.


小智 11

https://www.google.com/settings/security/lesssecureapps并将其激活. https://accounts.google.com/b/0/DisplayUnlockCaptcha并将其激活.

'port'=> env('MAIL_PORT',587),
'encryption'=> env('MAIL_ENCRYPTION','tls'),


小智 5

我有很多问题无法找到答案。然后,经过大量的反复试验,我找到了解决方案。上面的大多数解决方案都适用于其他解决方案,但最多可以帮助我50%。

因此,这就是它对我的工作方式(100%):

  1. 在Google中激活两步验证
  2. 现在,您将能够创建应用程序。打开它。
  3. 创建新应用(其他应用)并提供您的应用名称。
  4. 现在生成密码。

在laravel中,转到.env文件并进行更改

    MAIL_USERNAME= 'App Name you created'
    MAIL_PASSWORD= 'Generated Password for that app'
Run Code Online (Sandbox Code Playgroud)

这应该能够从您的Gmail帐户发送电子邮件。如果不适合您,请发表评论。


Sta*_*sik 3

您是否启用了两步谷歌身份验证?如果是这样,您需要定义一个新的“应用程序专用密码”密码: http: //www.google.com/landing/2step/