【发布时间】:2016-09-22 15:30:09
【问题描述】:
我已经在 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
}
}
注意我刚刚将 PHPMailer 更新到最新版本以尝试解决问题,但没有任何改变!老版本 5.2.2 还是一样的问题!
编辑:我刚刚成功将一封电子邮件发送到谷歌并正确发送。这让我怀疑这是滞后问题还是类似的问题。有谁知道phpmailer在高负载下是如何工作的,或者高负载是否会导致上述错误?
【问题讨论】:
-
一个很常见的问题。你检查过google吗?
-
@Michael_B 当然。对我来说,标准流程是在发布到堆栈之前研究谷歌搜索结果的第一页。
-
我的标准流程是,当一个问题很常见时,就是提问。大多数人不像你那么勤奋:-)
-
@Michael_B 我试试 :) 如果你有什么想法,请告诉我。甚至可能很明显......有时需要别人才能看到我看不到的东西
-
@Rhopercy 是的,先生。正如我所说,这在 5.2.2 版本上工作了一整年,今天它坏了。所以我更新到最新版本,但无论如何都会看到同样的错误