[英]PHPMailer error: SMTP -> ERROR: Failed to connect to server
I try to google all the morning and i think i need Stackoverflow now!我整个早上都在尝试谷歌,我想我现在需要 Stackoverflow!
I wrote a simple script to send a mail (from hotmail to gmail) but i get this error:我写了一个简单的脚本来发送邮件(从 hotmail 到 gmail),但我收到了这个错误:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. SMTP -> ERROR: Failed to connect to server: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。 (10060)SMTP Connect() failed.
(10060)SMTP Connect() 失败。 Error
错误
This is the code:这是代码:
<?php
require_once("../includes/phpMailer/class.phpMailer.php");
require_once("../includes/phpMailer/class.smtp.php");
$to_name = "RECEIVER NAME";
$to = "RECEIVER@gmail.com";
$subject = "Mail test at " . strftime("%T", time());
$message = "This is a test message";
$message = wordwrap($message, 70);
$from_name = "MY NAME";
$from = "MY_EMAIL@hotmail.it";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtp.live.com";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "MY USERNAME (hotmail)";
$mail->Password = "MY PASSWORD (hotmail)";
$mail->FromName = $from_name;
$mail->From = $from;
$mail->AddAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body = $message;
$result = $mail->Send();
echo $result ? 'Sent' : 'Error';
?>
Another info is that not even the standard mail() function worked, and checking php info i found this:另一个信息是,甚至标准的 mail() 函数都不起作用,检查 php 信息我发现了这个:
sendmail_from - MY PROPER MAIL (hotmail) sendmail_from - 我的正确邮件(hotmail)
sendmail_path - no value sendmail_path - 没有价值
SMTP - localhost SMTP - 本地主机
smtp_port - 25 smtp_port - 25
Thank you!!谢谢!!
I believe port 25 is blocked on smtp.live.com.我相信 smtp.live.com 上的端口 25 被阻止。 I cannot connect to smtp.live.com:25 from here either.
我也无法从这里连接到 smtp.live.com:25。 Try using port 587 instead, with TLS.
尝试使用端口 587 和 TLS。 So, it would be:
所以,它会是:
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
I found a solution for this problem, try this我找到了解决这个问题的方法,试试这个
Check whether your PHP is using openSSL extension or not...!检查您的 PHP 是否正在使用openSSL扩展...!
Hope this method shall solve your problem...希望这个方法能解决你的问题...
You may want to check the supported ports.您可能需要检查支持的端口。 For instance, my host supports smtp via ports 25, 3535 and 80.
例如,我的主机通过端口 25、3535 和 80 支持 smtp。
Using port 80 worked for me使用端口 80 对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.