ping“smtp.gmail.com”可以通,為什麼PHPMAILer卻報錯

來源:互聯網
上載者:User
ping“smtp.gmail.com”可以通,為啥PHPMAILer卻報錯
在CMD裡ping一下GMAIL的SMTP伺服器可以通,

可是在網頁裡面做的發送email的程式,卻總是報錯:
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.


咋回事呢:

PHP code
IsSMTP(); $mail->SMTPAuth   = true;                  // enable SMTP authentication $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server $mail->Port       = 465;                   // set the SMTP port for the GMAIL server  $mail->Username   = "xxx@gmail.com";  // GMAIL username $mail->Password   = "xxx";            // GMAIL password   $mail->From       = "xxx@gmail.com"; $mail->FromName   = "xxx";  $mail->Subject    = "subject 111";  //$mail->Body       = "Hi,
This is the HTML BODY
"; //HTML Body $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); $mail->AddAddress("xxx@gmail.com", "xxx"); $mail->IsHTML(true); // send as HTML if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?>


------解決方案--------------------
探討

會不會是空間商做了限制呢?

我在本地測試,用163的郵箱可以發郵件;用GMAIL的也是顯示這個錯誤,開啟PHPMAILER的偵錯模式顯示:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you ……
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.