邮件程序错误:SMTP connect()失败,phpmailer通过smtp gmail

时间:2015-07-11 08:11:49

标签: php gmail phpmailer

 <?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 = "abc@gmail.com";
$mail->Password = "abcpassword";
$mail->SetFrom("abc@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("sameone@domain.com");
 if(!$mail->Send())
    {

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

我收到了消息:

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
任何人,都可以帮助找出问题所在以及如何解决它?

1 个答案:

答案 0 :(得分:0)

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

  1. 使用浏览器中的“abc@gmail.com”登录。
  2. 转到Allow less secure apps
  3. 点击“开启”单选按钮。
  4. 现在检查。您可以发送电子邮件