我真的希望你们中的一个人可以帮助我。我一直用这个拉着我的头发约2个小时。我的客户电子邮件服务器上的其中一个帐户遭到入侵,Google开始阻止我们发送电子邮件的企图。所以我试图从基本的PHP邮件命令切换到PHPMailer并通过Google的SMTP服务器发送。此客户使用Google专业版的所有帐户。PHP邮件与PHPMailer通过谷歌SMTP
我使用了以下内容:
$mail = new PHPMailer();
$mail->isSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('[email protected]', 'Jimmy');
$mail->Subject = $this->subject;
$body = $this->message;
//$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
$mail->AddAddress($this->to, 'bob');
if(!$mail->Send()) {
error_log("Mailer Error: " . $mail->ErrorInfo);
echo '[br /]Fail';
} else {
error_log("Message sent!");
echo '[br /]Pass';
}
我知道证书是正确的,因为我可以与他们登录。我已经做了所有种类的东西这个脚本,它正试图使用的帐户发送:从TLS
- 更改到SSL
- '疏通Captcha验证码的帐户
- 禁用2因素身份验证(它已经关闭)
- 启用“不够安全的应用”
我不知道还能做什么。这是我不断收到的错误:
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: STARTTLS
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: AUTH LOGIN
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:32 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2017-05-15 03:12:32 SMTP Error: Could not authenticate.
2017-05-15 03:12:32 CLIENT -> SERVER: QUIT
2017-05-15 03:12:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
有关密码命令失败的部分是我没有得到的部分。当我用这个电子邮件帐户登录时,这怎么会是错误的?
我已经看了大约15个关于这个主题的话题,而他们的建议都没有解决我的问题。这是一个谷歌专家帐户,我的客户通过谷歌运行,所以它不会是'免费'限制的事情。
差不多*你发现,*和*排除指南这些线程中的每一个*,会告诉你**设置'SMTPDebug = 2' **。当它设置为1时,你不会看到服务器说的任何东西。 – Synchro
如果您将代码基于PHPMailer提供的gmail示例,那么首先您就不会陷入这个难题。 – Synchro
@Synchro - 我确实已将它设置为2,并且没有提供任何其他有用的信息。你的第二条评论没有帮助。我有我的代码镜像PHPMailer的例子,它的许多变化和错误仍然存在。我完成了这个设置。我正在切换到外部邮件提供商。 –