【发布时间】:2012-05-26 06:12:01
【问题描述】:
这是我的 php 代码
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->From = "example@gmail.com";
$mail->AddAddress("example@yahoo.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
我的 php.ini 有这个邮件配置 [邮件功能]
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from =example@gmail.com
我的错误是
以下发件人地址失败:example@gmail.com 邮件未发送 sent.Mailer 错误:以下发件人地址失败:example@gmail.com SMTP 服务器错误:5.7.0 必须先发出 STARTTLS 命令。 i1sm13250552pbv.49
请帮助我。提前谢谢......
【问题讨论】:
-
如果您当前正在从 localhost 运行该代码,那可能是您的问题
-
尝试将 $Host 更改为
ssl://smtp.gmail.com。 -
我尝试了“ssl://smtp.gmail.com”但再次显示
SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.