php不能连接到smtp,php – 无法连接到SMTP主机

宋昕
2023-12-01

SMTP Error: Could not connect to SMTP host. Message could not be sent.

Mailer Error: SMTP Error: Could not connect to SMTP host.

我似乎找不到使PHPMailer在CentOS下工作的方法.邮件工作在Windows下使用XAMPP,但我总是在Linux下得到这个错误.

SMTP服务器是在端口25上侦听的Lotus Domino,CentOS机器根本没有防火墙,奇怪的是即使是mail()也不起作用.它返回任何东西(在Windows上返回1).如果我通过telnet通过CentOS服务器发送电子邮件,它工作得很好,所以我不认为这是一个网络问题.它必须与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.

";

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 . '
';

}

return false;

}

看起来它不能打开Socket …

更新:使用$mail-> SMTPDebug = 2;据Alvaro的建议,

SMTP -> ERROR: Failed to connect to server: Permission denied (13)

 类似资料: