我已经在PHP服务器上运行PHPMailer一年了.一切都很好,直到3天前我开始收到以下错误:
SMTP错误:无法进行身份验证.
允许不太安全的应用程序打开
这是代码:
function SendEmail($to,$cc,$bcc,$subject,$body) {
require 'PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = 1;
try {
$addresses = explode(',', $to);
foreach ($addresses as $address) {
$mail->AddAddress($address);
}
if($cc!=''){
$mail->addCustomHeader("CC: " . $cc);
}
if($bcc!=''){
$mail->addCustomHeader("BCC: " . $bcc);
}
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
$mail->Username = "myemail@gmail.com"; // SMTP username
$mail->Password = "myemailpass"; // SMTP password
$webmaster_email = "myemail@gmail.com"; //Reply to this email ID
$name=$email;
$mail->From = $webmaster_email;
$mail->FromName = "Service";
//$mail->AddReplyTo($webmaster_email, "DiFractal Customer Service");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject;
$mail->Body = $body;
return $mail->Send();
} catch (phpmailerException $e) {
$myfile = fopen("debug_email.txt", "w");
fwrite($myfile,$e->errorMessage() . "\n" . $mail->ErrorInfo);
fclose($myfile);//Pretty error messages from PHPMailer
} catch (Exception $e) {
$myfile = fopen("debug_email_stp.txt", "w");
fwrite($myfile,$e->getMessage());
fclose($myfile);//Pretty error messages from PHPMailer
}
}
Run Code Online (Sandbox Code Playgroud)
注意我刚刚将PHPMailer更新到最新版本以尝试解决问题但没有任何改变!旧版本5.2.2仍然存在同样的问题!
编辑:我只有一个成功的电子邮件进入谷歌并正确发送.现在让我怀疑它是否存在滞后问题或类似问题.有谁知道phpmailer如何在高负载下运行,或者如果高负载会导致上述错误?
请务必检查谷歌的使用限制!PHPMailer 不会告诉您详细信息,它只会给您“无法验证”错误,但原因可能是因为您的限制。
@ https://support.google.com/a/answer/166852?hl=en
升级到 Google Business 的新帐户并切换到该帐户。问题解决了。