PHPMailer error: SMTP -gt; ERROR: Failed to connect to server(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 ->错误:无法连接到服务器
基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01