簡體   English   中英

帶有GMail的PHPMailer:SMTP錯誤

[英]PHPMailer with GMail: SMTP Error

我正在利用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上的另一台服務器並且它正在發送郵件。 如果沒有,請解釋。

我該如何解決這個問題?

謝謝大家的幫助

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

我建議也檢查一下,它的phpmailer是為使用gmail而定制的。 PHPGMailer

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

你會發現它有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM