SMTP Error: Could not connect to SMTP host. Message could not be sent.無法連接到SMTP主機
Mailer Error: SMTP Error: Could not connect to SMTP host.
我似乎無法找到一種方法,使CentOS的下PHPMailer的工作。 Mail在XAMPP下的Windows下工作得很好,但是我總是在Linux下得到這個錯誤。
SMTP服務器是監聽端口25的Lotus Domino,CentOS機器根本沒有防火牆,奇怪的是即使郵件()也不起作用。它什麼也沒有返回(在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 = "[email protected]";
$mail->FromName = "XXX";
$mail->AddAddress("[email protected]");
$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方法連接()):
$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;
}
看起來它無法打開插座...
更新:使用$ mail-> SMTPDebug = 2;阿爾瓦羅的建議產生這樣的輸出:
SMTP -> ERROR: Failed to connect to server: Permission denied (13)
您是否試過指定登錄憑據? –
沒有。這是什麼意思?你的意思是把它們設置爲「」? – raz3r
FYI tryed '$ mail-> SMTPAuth = true; $ mail-> Username =「」; $ mail-> Password =「」;' 剛纔,沒有運氣。 – raz3r