duanli8577
2015-04-21 07:16
浏览 74
已采纳

无法使用带有Gmail帐户的phpmailer发送电子邮件

I readly feel confused why i test many many example and correct example to send email with php mailer with gmail account but it did not work,here is the error

> 2015-04-21 07:06:50   CLIENT -> SERVER: EHLO www.ariarules.com
 2015-04-21 07:06:50    CLIENT -> SERVER: STARTTLS
 2015-04-21 07:06:50    CLIENT -> SERVER: EHLO www.ariarules.com
 2015-04-21 07:06:50    CLIENT -> SERVER: AUTH LOGIN
 2015-04-21 07:06:50    CLIENT -> SERVER:
 2015-04-21 07:06:52    SMTP ERROR: Username command failed:   
 535          Incorrect authentication data
 2015-04-21 07:06:52    SMTP Error: Could not authenticate.
 2015-04-21 07:06:52    CLIENT -> SERVER: QUIT
 2015-04-21 07:06:52    SMTP connect() failed.
 Mailer Error: SMTP connect() failed.

and my code

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; 
$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 = "googleaccount@gmail.com";
$mail->Password = "pass";
$mail->SetFrom("user@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("user@gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}

at end it's better to know i test tls & ssl with port 465 & 587 but....

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

我觉得很困惑,为什么我测试了许多例子和正确的例子来发送带有Gmail邮件的电子邮件和gmail帐户的电子邮件但是它 没有用,这是错误

 >  2015-04-21 07:06:50客户 - > 服务器:EHLO www.ariarules.com 
 2015-04-21 07:06:50客户 - > 服务器:STARTTLS 
 2015-04-21 07:06:50客户 - > 服务器:EHLO www.ariarules.com 
 2015-04-21 07:06:50客户 - > 服务器:AUTH LOGIN 
 2015-04-21 07:06:50客户 - > 服务器:
 2015-04-21 07:06:52 SMTP错误:用户名命令失败:
 535验证数据不正确
 2015-04-21 07:06:52 SMTP错误:无法验证。
 2015-  04-21 07:06:52客户 - > 服务器:退出
 2015-04-21 07:06:52 SMTP连接()失败。
邮件程序错误:SMTP连接()失败。
   
 
 

和 我的代码

  $ mail = new PHPMailer();  //创建一个新对象
 $ mail-> IsSMTP();  //启用SMTP 
 $ mail-> SMTPDebug = 1;  
 $ mail-> SMTPAuth = true;  //启用身份验证
 $ mail-> SMTPSecure ='tls';  //启用安全传输GMail 
 $ mail-> Host =“smtp.gmail.com”; 
 $ mail-> Port = 587;  //或587 
 $ mail-> IsHTML(true); 
 $ mail-> Username =“googleaccount@gmail.com”; 
 $ mail-> Password =“pass”; 
 $ mail  - > SetFrom(“user@gmail.com”); 
 $ mail-> Subject =“Test”; 
 $ mail-> Body =“hello”; 
 $ mail-> AddAddress(“  user@gmail.com“); 
if(!$ mail-> Send())
 {
echo”Mailer Error:“。  $ mail-> ErrorInfo; 
} 
else 
 {
echo“已发送消息”; 
} 
   
 
 

最后知道更好 我测试tls& ssl与端口465& 587但....

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

3条回答 默认 最新

  • dongtuo2373 2015-04-21 10:01
    已采纳

    enable "Access for less secure apps" :

    https://www.google.com/settings/security/lesssecureapps

    点赞 打赏 评论
  • drl6054 2015-04-21 07:24

    gmail does not allow to send emails from less secured applications. there is an option 'access for less secured apps' in google account settings. turn that on and you will be able to send emails.

    点赞 打赏 评论
  • dou91736 2015-04-21 09:39

    i was facing same issue some days before . i found this solution , may be it works for you.Pass your values like this. its strange but worked for me.

    $username="googleaccount@gmail.com";
    $password="pass":
    $mail->Username = $username;
    $mail->Password = $password;
    
    点赞 打赏 评论

相关推荐 更多相似问题