SMTP错误:无法连接到SMTP主机.无法发送消息.
邮件程序错误:SMTP错误:无法连接到SMTP主机.
我似乎找不到让PHPMailer在CentOS下工作的方法.使用XAMPP在Windows下邮件工作正常,但我总是在Linux下遇到此错误.
SMTP服务器是在端口25上侦听的Lotus Domino,CentOS机器根本没有防火墙,奇怪的是即使mail()也不起作用.它什么都不返回(在Windows上返回1).如果我通过CentOS服务器通过telnet发送电子邮件,它可以正常工作,所以我不认为这是一个网络问题.它必须与PHP相关,但我不知道如何.
<?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";
?>
Run Code Online (Sandbox Code Playgroud)
只是为了澄清上面的代码适用于XAMPP(Windows).
我在PHPMailer上调试了错误,这里发生错误(class.smtp.php方法Connect()):
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // …Run Code Online (Sandbox Code Playgroud)