phpmailer似乎无法使用gmail

时间:2017-01-27 18:52:05

标签: smtp gmail phpmailer

当我尝试使用带有gmail stp的phpmailer发送电子邮件时,似乎无法正常工作。我已经测试了所有提出的解决方案,但仍然是这个问题:

2017-01-27 19:29:33 Invalid address:  (addAnAddress Reply-To): jgh
2017-01-27 19:29:33 SERVER -> CLIENT: 220-khadija.genious.net ESMTP Exim 4.87 #1 Fri, 27 Jan 2017 19
:29:33 +0000 
                                      220-We do not authorize the use of this system to transport unsolicited
, 
                                      220 and/or bulk e-mail.
2017-01-27 19:29:33 CLIENT -> SERVER: EHLO www.mywebsite.ma
2017-01-27 19:29:33 SERVER -> CLIENT: 250-khadija.genious.net Hello khadija.genious.net [41.77.119.226
]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      250 HELP
2017-01-27 19:29:33 CLIENT -> SERVER: STARTTLS
2017-01-27 19:29:33 SERVER -> CLIENT: 220 TLS go ahead
2017-01-27 19:29:33 CLIENT -> SERVER: EHLO www.mywebsite.ma
2017-01-27 19:29:33 SERVER -> CLIENT: 250-khadija.genious.net Hello khadija.genious.net [41.77.119.226
]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250 HELP
2017-01-27 19:29:33 CLIENT -> SERVER: AUTH LOGIN
2017-01-27 19:29:33 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-01-27 19:29:33 CLIENT -> SERVER: xxx==
2017-01-27 19:29:33 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2017-01-27 19:29:33 CLIENT -> SERVER: xxx
2017-01-27 19:29:35 SERVER -> CLIENT: 535 Incorrect authentication data
2017-01-27 19:29:35 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2017-01-27 19:29:35 SMTP Error: Could not authenticate.
2017-01-27 19:29:35 CLIENT -> SERVER: QUIT
2017-01-27 19:29:35 SERVER -> CLIENT: 221 khadija.genious.net closing connection
2017-01-27 19:29:35 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

这是我的php页面:

require 'class.phpmailer.php';
require 'class.smtp.php';

header('Content-Type: application/json');

$mail = new PHPMailer;

$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "XXX@gmail.com";
$mail->Password = "XXX";

$email_recipient = 'XXX@gmail.com';

$mail->setFrom($email_recipient);
$mail->addAddress($email_recipient);  
$mail->addReplyTo($_POST['email']);

$mail->isHTML(true);

$mail->Subject = 'Subject';
$mail->Body    = "Message";

if(!$mail->send()) {
    echo json_encode(array('result' => false));
} else {
    echo json_encode(array('result' => true));
}

我已经启用了lesssecureapps:https://www.google.com/settings/security/lesssecureapps

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:2)

您的ISP正在将SMTP连接重定向到自己的邮件服务器。您要求连接到smtp.gmail.com,但最终结果是khadija.genious.net,当然您的凭据在那里无效。

我猜你正在运行超过5.6的PHP;这是一个很好的教训,为什么不验证TLS证书是一个坏主意 - 您已经有效地向MITM攻击者赠送了Gmail凭据。故障排除指南中对此进行了介绍。