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

无法使用带有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....

  • 写回答

3条回答 默认 最新

  • dongtuo2373 2015-04-21 10:01
    关注

    enable "Access for less secure apps" :

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀