提问者:小点点

PHPMailer-无法进行身份验证


我已经在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在高负载下是如何工作的吗?或者高负载会导致上述错误吗?


共3个答案

匿名用户

试着去:myaccount.google.com-

匿名用户

我遇到了类似的问题,需要设置起始地址

$mail->setFrom('myemail@gmail.com', 'Webmaster');

匿名用户

确保你检查谷歌的使用限制!PHPMailer不会告诉你细节,它只会给你无法验证错误,但原因可能是因为你的限制。

@ https://support.google.com/a/answer/166852?hl=en

升级到谷歌业务的新账户,然后切换到该账户。问题解决了。