【发布时间】:2016-10-25 10:58:45
【问题描述】:
我正在尝试使用PHPMailer 发送带有 pdf 附件的邮件。
代码:
include_once("./PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "username@gmail.com";
$mail->Password = "accual password";
$mail->SetFrom("test1@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("test2@gmail.com");
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
错误:
2016-10-25 10:40:27 CLIENT -> SERVER: EHLO test.something.com
2016-10-25 10:40:27 CLIENT -> SERVER: STARTTLS
2016-10-25 10:40:27 CLIENT -> SERVER: EHLO test.something.com
2016-10-25 10:40:27 CLIENT -> SERVER: AUTH LOGIN
2016-10-25 10:40:27 CLIENT -> SERVER: ... user name removed ...
2016-10-25 10:40:27 CLIENT -> SERVER: ... password removed ...
2016-10-25 10:40:27 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials cy7sm4615595wjc.26 - gsmtp
2016-10-25 10:40:27 SMTP Error: Could not authenticate.
2016-10-25 10:40:27 CLIENT -> SERVER: QUIT
2016-10-25 10:40:27 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshootingthanks
我该如何解决这个问题?我感谢所有的回应。先谢谢了。
【问题讨论】:
-
顺便说一句 - 您可能想要更改密码,因为它包含在 SMTP 输出中。
-
您的代码基于具有误导性 cmets 的过时示例。确保您使用的是最新版本,并阅读错误指向您的文档。你会发现
SMTPDebug = 2对你有很大帮助。