GMail用户名和密码不被接受的错误

GMail用户名和密码不被接受的错误

本文介绍了使用SwiftMailer发送电子邮件时,GMail用户名和密码不被接受的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用我的GMail帐户从我的 PHP应用程序发送电子邮件时,出现以下错误>与SwiftMailer.

I get the following error when trying to use my GMail account to send an email from my PHP application with SwiftMailer.

535-5.7.8 Username and Password not accepted

这是我的SwiftMailer代码:

This is my SwiftMailer code:

$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
    ->setUsername('[email protected]')
    ->setPassword('~password-in-here~');

$mailer  = Swift_Mailer::newInstance($transporter);
$message = Swift_Message::newInstance('Portfolio Enquiry')
    ->setFrom(array('[email protected]' => 'CRMPicco Portfolio Enquiry'))
    ->setTo(array('[email protected]' => 'A name'))
    ->setBody($email_body);

$result = $mailer->send($message);

这是我的Apache错误日志和堆栈跟踪中的条目.

This is the entry in my Apache error log and the stack trace.

我尝试了 http://www.google.com/accounts/DisplayUnlockCaptcha 和我可以通过网络浏览器登录到该帐户,而不会出现任何问题.

I have tried http://www.google.com/accounts/DisplayUnlockCaptcha and I can log in to the account through a web browser without any problems.

这发生在我的本地开发机器和公众可访问的站点上.这是我的GMail帐户或我的实施问题吗?

This happens on my local development machine and the publically-accesible site. Is this an issue with my GMail account or my implementation?

推荐答案

您需要允许从不太安全的应用访问,因为通过密码进行的IMAP本质上是不安全的. (不可撤消)

You need to allow access from less-secure apps, because IMAP via password is fundamentally insecure. (it's non-revocable)

更好的是,切换到OAuth身份验证.

Better yet, switch to OAuth authentication.

这篇关于使用SwiftMailer发送电子邮件时,GMail用户名和密码不被接受的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 01:58