Could not connect to SMTP host(无法连接到 SMTP 主机)
问题描述
SMTP 错误:无法连接到 SMTP 主机.无法发送消息.
SMTP Error: Could not connect to SMTP host. Message could not be sent.
邮件程序错误:SMTP 错误:无法连接到 SMTP 主机.
Mailer Error: SMTP Error: Could not connect to SMTP host.
我似乎找不到让 PHPMailer 在 CentOS 下工作的方法.邮件在带有 XAMPP 的 Windows 下工作得很好,但在 Linux 下我总是收到这个错误.
I can't seem to find a way to make PHPMailer work under CentOS. Mail work just fine under Windows with XAMPP but I always get this error under Linux.
SMTP 服务器是一个侦听端口 25 的 Lotus Domino,CentOS 机器根本没有防火墙,奇怪的是即使 mail() 也不起作用.它什么也不返回(而在 Windows 上返回 1).如果我通过 CentOS 服务器通过 telnet 发送电子邮件,它工作得很好,所以我认为这不是网络问题.应该是和PHP相关的,但是不知道怎么弄的.
The SMTP server is a Lotus Domino listening on port 25, CentOS machine has NO firewall at all and the strange thing is that even mail() does not work. It returns nothing (while on Windows returns 1). If I send an email through telnet via CentOS server it works just fine so I don't think it is a network problem. It must be related to PHP but I don't know how.
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "192.168.x.x";
$mail->SMTPAuth = false;
$mail->From = "xxx@xxx.it";
$mail->FromName = "XXX";
$mail->AddAddress("xxx@xxx.it");
$mail->IsHTML(true);
$mail->Subject = "Test";
$mail->Body = "Test";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
只是为了澄清上面的代码适用于 XAMPP (Windows).
Just to clarify the code above works on XAMPP (Windows).
我在PHPMailer上调试了错误,错误发生在这里(class.smtp.php方法Connect()):
I debugged the error on PHPMailer and error happens here (class.smtp.php method Connect()):
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // error message if any
$tval); // give up after ? secs
// verify we connected properly
if(empty($this->smtp_conn)) {
$this->error = array("error" => "Failed to connect to server",
"errno" => $errno,
"errstr" => $errstr);
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
}
return false;
}
好像打不开Socket……
It looks like it can't open the Socket...
更新: 使用 $mail->SMTPDebug = 2;正如阿尔瓦罗所建议的那样产生了这个输出:
UPDATE: Using $mail->SMTPDebug = 2; as suggested by Alvaro produced this output:
SMTP ->错误:无法连接到服务器:权限被拒绝 (13)
SMTP -> ERROR: Failed to connect to server: Permission denied (13)
推荐答案
您可以使用 SMTPDebug
属性启用调试模式,例如:
You can enable debug mode with the SMTPDebug
property, e.g.:
$mail = new PHPMailer();
// 1 = errors and messages
// 2 = messages only
$mail->SMTPDebug = 2;
错误消息将回显到屏幕.
Error messages will be echoed to screen.
更新:
使用 fsockopen() 的 permission denied 错误消息表明用户 PHP 运行as 是不允许打开套接字的.如果您仔细检查是否没有防火墙,则可能是 SELinux 问题 :-?
A permission denied error message using fsockopen() suggests that the user PHP runs as is not allowed to open a socket. If you'd double-checked that there's no firewall, it's possible that's a SELinux problem :-?
这篇关于无法连接到 SMTP 主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法连接到 SMTP 主机
基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01