SMTP错误:无法连接到SMTP主机。无法发送消息。
邮件程序错误:SMTP错误:无法连接到SMTP主机。
我似乎找不到在CentOS下使PHPMailer工作的方法。在Windows上使用XAMPP可以很好地发送电子邮件,但在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";
?>
仅澄清一下,上面的代码适用于 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, // 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...
更新:按照Alvaro的建议使用$mail->SMTPDebug = 2;,产生了以下输出:
SMTP -> 错误:无法连接到服务器:权限被拒绝(13)