沃梦达 / 编程问答 / php问题 / 正文

PHPMailer 错误:SMTP ->错误:无法连接到服务器

PHPMailer error: SMTP -gt; ERROR: Failed to connect to server(PHPMailer 错误:SMTP -错误:无法连接到服务器)

本文介绍了PHPMailer 错误:SMTP ->错误:无法连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整个早上都在尝试谷歌,我想我现在需要 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 -> ERROR: Failed to connect to server: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应.(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:

sendmail_from - 我的正确邮件(hotmail)

sendmail_from - MY PROPER MAIL (hotmail)

sendmail_path - 没有值

sendmail_path - no value

SMTP - 本地主机

SMTP - localhost

smtp_port - 25

smtp_port - 25

谢谢!!

推荐答案

我相信 smtp.live.com 上的 25 端口被封锁了.我也无法从这里连接到 smtp.live.com:25.尝试使用端口 587 和 TLS.所以,应该是:

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 ->错误:无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHPMailer 错误:SMTP ->错误:无法连接到服务器

基础教程推荐