首页 文章

带有GMail的PHPMailer:SMTP错误

提问于
浏览
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上的另一台服务器并且它正在发送邮件 . 如果没有,请解释 .

我该如何解决这个问题?

谢谢大家的帮助

2 回答

  • 4

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

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

  • 2

    要将PHPMailer与gmail一起使用,请不要使用SSL / 465(自1998年以来已被弃用),使用TLS / 587作为Noctrine建议,以下是:

    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
    ...
    

    你应该发现它有效 .

相关问题