【问题标题】:how to solve password command failed Error While sending mail in php如何解决密码命令失败的错误在php中发送邮件时
【发布时间】:2015-03-02 19:34:39
【问题描述】:

谁能帮我找出以下代码有什么问题,因为当我尝试在 php 中发送邮件时,我收到以下错误

2015-01-05 09:18:20 CLIENT -> SERVER: EHLO localhost 
2015-01-05 09:18:20 CLIENT -> SERVER: AUTH LOGIN 
2015-01-05 09:18:20 CLIENT -> SERVER: cGV0ZXJwcm9ncmFtZXIxOTkxQGdtYWlsLmNvbQ==  
2015-01-05 09:18:20 CLIENT -> SERVER: bWFuaTE5OTE= 
2015-01-05 09:18:21 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 xq4sm53656187pbb.21 - gsmtp 
2015-01-05 09:18:21 CLIENT -> SERVER: QUIT 
2015-01-05 09:18:21 SMTP connect() failed. Mailer Error: SMTP connect() failed.

代码..

<?php
require "PHPMailerAutoload.php";
$mail = new PHPMailer(); 
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->Mailer="smtp";
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = 'peter1991@gmail.com';
$mail->Password = 'password';
$mail->SMTPAuth = true;
$mail->From = 'peter1991@gmail.com';
$mail->FromName = 'peter';
$mail->AddAddress('manikandan@gmail.com');
$mail->AddReplyTo('john1991@gmail.com', 'John');
$mail->IsHTML(true);
$mail->Subject    = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
$mail->Body    = "Hello";
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
?>

如果我的猜测是正确的,那么 gmail 肯定存在一些凭证问题,但我完全感到困惑,我正处于大学项目的中间,如果不解决这个问题,我将无法继续前进。 欢迎任何帮助提前谢谢

【问题讨论】:

  • 我已经尝试了互联网上的所有示例,但没有前任帮助我解决这个问题。
  • 我猜你尝试了所有的例子,除了一个重要的例子 - the one that's bundled with PHPMailer

标签: php email gmail phpmailer


【解决方案1】:

$mail->SMTPSecure = 'ssl'; $mail->Host = 'smtp.gmail.com'; 试试看

【讨论】:

  • 不要在 465 上使用 ssl;在 587 上使用 tls。
  • @Synchro 请解释一下,为什么?
  • 因为它是deprecated since 1998!这是不到一年的 RFC 推荐! PHP 不受微软编写的影响,因此不需要使用过时的标准。 465 上的 SSL 在 gmail 上仍然有效(因为 gmail 确实必须迎合坏客户),但没有充分的理由使用它,所以避免它是一个好习惯。
【解决方案2】:

试试这个:

$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->Username = "test@gmail.com";
$mail->Password = "test";

【讨论】:

  • 不要在 465 上使用 ssl;在 587 上使用 tls。
猜你喜欢
  • 2014-03-23
  • 1970-01-01
  • 2018-05-23
  • 1970-01-01
  • 2014-06-25
  • 1970-01-01
  • 2014-07-22
  • 2018-05-17
相关资源
最近更新 更多