4

我正在使用 PHPMailer 通过 GMail 发送邮件。我使用的代码直接来自教程,它可以在我的笔记本电脑上完美运行。但是,在 Windows 2003 Server 上对此进行测试 - 它似乎总是返回一个 SMPT 错误:

SMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。

这是我在 PHPMailer 中使用的设置:

include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // use ssl
$mail->Host = "smtp.gmail.com"; // GMAIL's SMTP server
$mail->Port = 465; // SMTP port used by GMAIL server

我可以自信地说这不是端口问题,因为我正在连接到端口 465 上的另一台服务器并且它正在发送邮件。如果不是,请解释。

我该如何解决这个问题?

谢谢大家的帮助

4

2 回答 2

4

首先要注意的是:Gmail 使用 TLS。不知道使用 SSL 代替 TLS 是否会有很大的不同,但 SSL 是 TLS 的前身。

我还建议检查一下,它的 phpmailer 是为使用 gmail 而定制的。PHPGMailer

于 2010-05-19T18:16:47.247 回答
2

要将 PHPMailer 与 gmail 一起使用,请不要使用 SSL/465(自 1998 年以来已弃用),按照 Noctrine 的建议使用 TLS/587,方法如下:

include 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "tls://smtp.gmail.com"; // GMAIL's SMTP server
$mail->Port = 587; // SMTP port used by GMAIL server
...

你应该会发现这行得通。

于 2013-03-22T13:23:36.430 回答