2015-07-11 248 views
0
<?php 
require_once ("PHPMailer-master/PHPMailerAutoload.php"); 
$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail 
//$mail->SMTPSecure = 'tls'; 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "abcpassword"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress("[email protected]"); 
if(!$mail->Send()) 
    { 

     echo "Mailer Error: " . $mail->ErrorInfo; 
    } 
    else 
    { 
    echo "Message has been sent"; 
    } 
?> 

我得到的消息:邮件错误:SMTP连接()通过SMTP的Gmail失败,PHPMailer的

2015-07-11 08:06:17 CLIENT -> SERVER: EHLO action.ticambodia.org 
2015-07-11 08:06:17 CLIENT -> SERVER: AUTH LOGIN 
2015-07-11 08:06:17 CLIENT -> SERVER: c29lbmdrYW5lbEBnbWFpbC5jb20= 
2015-07-11 08:06:17 CLIENT -> SERVER: a2FuZWxAbjB3 2015-07-11 08:06:17 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 mg19sm5958238oeb.10 - gsmtp 
2015-07-11 08:06:17 SMTP Error: Could not authenticate. 
2015-07-11 08:06:17 CLIENT -> SERVER: QUIT 
2015-07-11 08:06:17 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

任何人,可以帮助找出是什么问题,如何解决呢?

+2

错误似乎很明显 – 2015-07-11 08:16:18

+2

如果您表现出丝毫尝试自己解决问题,尤其是当好的建议坐在您面前时,您会获得更多的同情。 **阅读您的错误信息**。如果您按照所提供的文档链接,它会完全告诉您*您需要做什么来解决您的问题。您还将代码基于旧示例 - 确保您使用的是最新的PHPMailer。 – Synchro

回答

0

错误来自Google方面。出于安全原因,Google阻止安全性较低的应用访问您的邮件。但是你可以关闭它。

  1. 用你的浏览器使用“[email protected]”进行登录。
  2. 转至Allow less secure apps
  3. 单击“打开”单选按钮。

现在检查。您可以发送电子邮件