php – 无法连接到SMTP主机

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相关,但我不知道如何.

<?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 …

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

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

您可以使用SMTPDebug属性启用调试模式,例如:
$mail = new PHPMailer();
// 1 = errors and messages
// 2 = messages only
$mail->SMTPDebug  = 2;

错误消息将回显到屏幕.

更新:

使用fsockopen()的权限被拒绝的错误消息表明用户PHP运行不允许打开套接字.如果你仔细检查没有防火墙,那可能是SELinux problem: – ?

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...