有人可以帮我找到以下代码有什么问题,因为当我尝试在php中发送邮件时,我收到以下错误
2015-01-05 09:18:20 CLIENT -> SERVER: EHLO localhost
2015-01-05 09:18:20 CLIENT -> SERVER: AUTH LOGIN
2015-01-05 09:18:20 CLIENT -> SERVER: cGV0ZXJwcm9ncmFtZXIxOTkxQGdtYWlsLmNvbQ==
2015-01-05 09:18:20 CLIENT -> SERVER: bWFuaTE5OTE=
2015-01-05 09:18:21 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 xq4sm53656187pbb.21 - gsmtp
2015-01-05 09:18:21 CLIENT -> SERVER: QUIT
2015-01-05 09:18:21 SMTP connect() failed. Mailer Error: SMTP connect() failed.
代码..
<?php
require "PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->Mailer="smtp";
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = 'peter1991@gmail.com';
$mail->Password = 'password';
$mail->SMTPAuth = true;
$mail->From = 'peter1991@gmail.com';
$mail->FromName = 'peter';
$mail->AddAddress('manikandan@gmail.com');
$mail->AddReplyTo('john1991@gmail.com', 'John');
$mail->IsHTML(true);
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = "Hello";
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
?>
如果我的猜测是正确的,那么gmail肯定存在一些凭证问题,但我完全感到困惑,我正处于大学项目的中间,如果不解决这个问题我就无法继续前进。 任何帮助都欢迎提前感谢
答案 0 :(得分:0)
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
试一试
答案 1 :(得分:0)
试试这个:
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->Username = "test@gmail.com";
$mail->Password = "test";