douhuiyan2772
2016-04-07 05:04
浏览 84
已采纳

通过PHPMailer发送电子邮件时身份验证错误

Following is the code that I am using for sending mail using PHPMailer but getting error.

 public function changePassword(){
   if($this->request->is('post')){
   require_once(ROOT .DS. 'vendor' . DS  . 'PHPMailer' . DS .  'class.phpmailer.php');
   $email = 'abc@gmail.com';
   $mail = new PHPMailer(); // create a new object
   $mail->IsSMTP(); // enable SMTP
   $mail->isHTML(true);
   $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
   $mail->SMTPAuth = true; // authentication enabled
   $mail->SMTPSecure = 'TLS'; // secure transfer enabled REQUIRED for Gmail
   $mail->Host = "smtp.gmail.com";
   $mail->Port = 587; // or 587
   $mail->IsHTML(true);
   $mail->Username = "xyz@gmail.com";
   $mail->Password = "dead_gone";
   $mail->SetFrom("xyz@gmail.com");
   $mail->AddAddress($email);
   $mail->Subject = "password recovery";
   $mail->Body = "your password is:- sdx_12345  click here to log in <a href ='http://localhost/cake/logins'> click here  </a>  ";

   if(!$mail->Send()) {
     echo "Mailer Error: " . $mail->ErrorInfo;
   } else {
       echo "mail sent";
     }
 }

}

ERROR:

SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first. v3sm8416695par.17 - gsmtp SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.

图片转代码服务由CSDN问答提供 功能建议

以下是我用于使用PHPMailer发送邮件但收到错误的代码。 \ n

  public function changePassword(){
 if($ this-&gt; request-&gt; is('post')){
 require_once(ROOT .DS。'vendor'.DS.'PHPMailer  '。DS。'class.phpmailer.php'); 
 $ email ='abc@gmail.com'; 
 $ mail = new PHPMailer();  //创建一个新对象
 $ mail-&gt; IsSMTP();  //启用SMTP 
 $ mail-&gt; isHTML(true); 
 $ mail-&gt; SMTPDebug = 1;  //调试:1 =错误和消息,2 =仅消息
 $ mail-&gt; SMTPAuth = true;  //启用身份验证
 $ mail-&gt; SMTPSecure ='TLS';  //为Gmail启用安全传输
 $ mail-&gt; Host =“smtp.gmail.com”; 
 $ mail-&gt; Port = 587;  //或587 
 $ mail-&gt; IsHTML(true); 
 $ mail-&gt; Username =“xyz@gmail.com”; 
 $ mail-&gt; Password =“dead_gone”; 
 $ mail  - &gt; SetFrom(“xyz@gmail.com”); 
 $ mail-&gt; AddAddress($ email); 
 $ mail-&gt; Subject =“password recovery”; 
 $ mail-&gt; Body =  “您的密码是: -  sdx_12345点击此处登录&lt; a href ='http:// localhost / cake / logins'&gt;点击此处&lt; / a&gt;”; 
 
 if(!$ mail-&gt  ;发送()){
 echo“梅勒错误:”。  $ mail-&gt; ErrorInfo; 
} else {
 echo“mail sent”; 
} 
} 
   
 
 

}

错误:

SMTP - &gt; 错误:服务器不接受AUTH:530 5.7.0必须首先发出STARTTLS命令。 v3sm8416695par.17 - gsmtp SMTP错误:无法进行身份验证。 邮件程序错误:SMTP错误:无法进行身份验证。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongmei3869 2016-04-07 06:16
    已采纳

    This property is case-sensitive:

    $mail->SMTPSecure = 'tls'
    

    It would help if you based your code on the gmail example provided with PHPMailer - it's not as if you're the first to connect to gmail!

    点赞 打赏 评论
  • dongtuoleng8624 2016-04-07 05:25

    try a SSL connection over the port 465 and look at you security settings in you account from google

    点赞 打赏 评论
  • dtudj42064 2016-04-07 05:42

    You should also put

    $mail->IsHTML(true);
    

    after you set your body and attachments.

    Edit:

    It also might be possible that TLS has to be lowercase.

    点赞 打赏 评论

相关推荐 更多相似问题