我想知道问题出在哪里,因为我收到了身份验证错误。
include_once('phpmailer/class.phpmailer.php'); include_once('phpmailer/class.smtp.php'); //6nb5Drv; function sendmail(){ $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->SMTPAuth = true; // turn on SMTP authentication $mail->SMTPSecure = "tls"; $mail->Host = "smtp.gmail.com"; // specify main and backup server $mail->Port = 587; // Set the SMTP port i tried and 457 $mail->Username = 'newmail@gmail.com'; // SMTP username $mail->Password = 'newmailpass'; // SMTP password $mail->SMTPDebug = 1; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->From = 'from@yahoo.com'; $mail->FromName = 'From'; $mail->AddAddress('to@gmail.com', 'To'); // Add a recipient $mail->IsHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <strong>in bold!</strong>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo 'Message has been sent'; } sendmail();
但是我收到了身份验证错误。 怎么了? 可能是凭据的内容,如何配置gmail smtp?
调试报告:
2015-12-04 17:56:15客户 - &gt;服务器:EHLO www.site.co 2015-12-04 17:56:15客户 - &gt;服务器:STARTTLS 2015-12-04 17:56:15客户 - &gt;服务器:EHLO www.site.co 2015-12-04 17:56:15客户 - &gt;服务器:AUTH LOGIN 2015-12-04 17:56:15客户端 - &gt; 服务器:UHJlZGljdG9sb2d5 2015-12-04 17:56:15客户端 - &gt;服务器: U2dHZlB0VHZUbTZ1SW9ZMi1qTlNCQQ == 2015-12-04 17:56:17 SMTP错误: 密码命令失败:435 4.7.8错误:验证失败: UGFzc3dvcmQ6 2015-12-04 17:56:17 SMTP错误:无法进行身份验证。 2015-12-04 17:56:17客户 - &gt;服务器:退出2015-12-04 17:56:17 SMTP 连接失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting消息 无法发送.Mailer错误:SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
答案 0 :(得分:2)
根据这篇文章:
PHPMailer - SMTP ERROR: Password command failed when send mail from my server,在某些情况下,您必须指定谷歌这不是可疑活动,并在您的帐户中激活一些安全选项。
假设这是正确的密码...