我一直在PHP服務器上運行PHPMailer一年。一切都很好,直到4天前,當我開始收到以下錯誤:PHPMailer - 無法驗證
SMTP Error: Could not authenticate.
允許不夠安全的應用是ON
這裏是代碼:
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 = "[email protected]"; // SMTP username
$mail->Password = "myemailpass"; // SMTP password
$webmaster_email = "[email protected]"; //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 **](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=phpmailer%20gmail%20could%20not%20authenticate)? –
@Michael_B當然。對我而言,標準流程是在發佈堆棧之前,先研究谷歌搜索結果的第一頁。 –
對於我來說,當一個問題非常普遍時,標準流程就是詢問。大多數人不像你那麼勤奮:-) –