【发布时间】:2014-01-20 15:28:48
【问题描述】:
我有一个 PHPMailer 脚本,我检查了所有其他与此类似的线程,并尝试了该问题后面的所有解决方案。但这是我收到的错误
2014-01-03 02:25:16 SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed.
这是我的脚本:
$body = "test";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // I have also tried tls
$mail->SMTPKeepAlive = true;
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // I have also tried 25
$mail->Username = "xxxx@gmail.com"; // GMAIL username
$mail->Password = "xxxxx"; // GMAIL password
$mail->SetFrom("johndoe@gmail.com","John Doe");
$mail->AddReplyTo("johndoe@gmail.com","John Doe");
$mail->Subject = "Booking from " . $_POST['person'] . ' at ' . $_POST['name'];
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "johndoe@hotmail.co.uk";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
但是我无法让它工作。我尝试了许多不同的解决方案。我什至很高兴使用默认的 php 邮件,但我只需要发送它,php 邮件甚至无法通过 hotmail 垃圾邮件过滤器(我的意思是它甚至没有将其发送到垃圾邮件)。
这里有什么解决方案或建议吗?非常感谢!
【问题讨论】:
-
您是否排除了简单的防火墙问题?当它在本地工作而不是远程工作时,您可能正在写关于被阻止的端口。您可以使用 fsockopen 检查阻塞的端口,a-la stackoverflow.com/questions/2226374/…
-
你试过端口 587(用于 TLS)吗?
-
非常感谢!省了我一辈子的麻烦! +1!
-
你指的是我说的587端口吗? @Jarrod 只是出于好奇。
-
我在 SO 上找到了一个答案,其中包含在这个答案的评论中:stackoverflow.com/a/17144196/1415724 这就是我提到它的原因,希望它能解决问题。