![](/img/trans.png)
[英]PHP Mailer SMTP ERROR: Failed to connect to server: (0) but SMTP tester works
[英]SMTP connect() failed PHP mailer
我正在嘗試使用PHPMailer從我的hotmail帳戶發送電子郵件。 從我的PC可以正常工作,但是當我在另一台PC上嘗試時,出現以下錯誤消息:
2015-04-23 17:31:18客戶端->服務器:EHLO本地主機
2015-04-23 17:31:18客戶端->服務器:退出
2015-04-23 17:31:18 SMTP connect()失敗。 郵件錯誤
這是我的代碼:
<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->SMTPSecure = 'SSL';
$mail->Username = "b1sakher@hotmail.fr";
$mail->Password = "rerered";
$mail->AddAddress("b1sakher@hotmail.fr");
$mail->FromName = "My Name";
$mail->Subject = "My Subject";
$mail->Body = "My Body";
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
{
echo "Mailer Error";
}
else
{
echo "Message has been sent";
}
?>
首先,您應該在代碼中添加“調試模式”,這將告訴您哪里出了問題。
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant
我遇到了類似的問題,但發現它是Cpanel / WHM中的CFS防火牆阻止了該端口。
如果您無權訪問WHM,請詢問您的托管服務提供商。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.