PHPMailer错误:SMTP->错误:无法连接到服务器 [英] PHPMailer error: SMTP -> ERROR: Failed to connect to server
问题描述
我整个上午都在尝试Google,我认为我现在需要Stackoverflow!
I try to google all the morning and i think i need Stackoverflow now!
我写了一个简单的脚本来发送邮件(从hotmail到gmail) 但我收到此错误:
I wrote a simple script to send a mail (from hotmail to gmail) but i get this error:
SMTP->错误:无法连接到服务器:连接尝试失败,因为一段时间后被连接方未正确响应,或者由于连接的主机未能响应而建立的连接失败. (10060)SMTP Connect()失败.错误
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. (10060)SMTP Connect() failed. Error
这是代码:
<?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';
?>
另一个信息是,即使标准的mail()函数也无法正常工作,检查php信息后我发现:
Another info is that not even the standard mail() function worked, and checking php info i found this:
发送邮件自-我的正确邮件(hotmail)
sendmail_from - MY PROPER MAIL (hotmail)
sendmail_path-没有值
sendmail_path - no value
SMTP-本地主机
smtp_port-25
smtp_port - 25
谢谢!
推荐答案
我相信smtp.live.com上的端口25被阻止.我也无法从此处连接到smtp.live.com:25.尝试使用带TLS的端口587代替.因此,它将是:
I believe port 25 is blocked on smtp.live.com. I cannot connect to smtp.live.com:25 from here either. Try using port 587 instead, with TLS. So, it would be:
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
这篇关于PHPMailer错误:SMTP->错误:无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!