【发布时间】:2015-09-06 02:14:40
【问题描述】:
我正在尝试使用 phpmailer 发送电子邮件。这是我写的代码。
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'shamir.towsif@gmail.com';
$mail->Password = '*********';
$mail->Port = 25;
$mail->From = 'shamir.towsif@gmail.com';
$mail->FromName = 'Shamir Towsif';
$mail->addAddress('shamir.towsif@gmail.com', 'Shamir Towsif');
$mail->addReplyTo('shamir.towsif@gmail.com', 'Information');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo "Message could not be sent.\n";
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
这是我得到的错误。
Message could not be sent. Mailer Error: SMTP connect() failed.
我做错了什么。 SO中的其他问题没有帮助。提前致谢。
【问题讨论】:
-
您是否对您的 Google 帐户使用双重身份验证?你确认你的密码是正确的吗?如果是这样,请尝试镜像函数调用here。
-
您真的阅读了所有 800 多个关于 SO 上此确切错误消息的其他问题吗?我印象深刻!我猜the documentation 也没有帮助。
标签: php email smtp gmail phpmailer