无法连接到SMTP主机 [英] Could not connect to SMTP host

查看:418
本文介绍了无法连接到SMTP主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SMTP错误:无法连接到SMTP主机.无法发送消息.

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

邮件错误:SMTP错误:无法连接到SMTP主机.

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

我似乎找不到一种使PHPMailer在CentOS下工作的方法.在XAMPP的Windows下,邮件工作正常,但是在Linux下,我总是会收到此错误.

I can't seem to find a way to make PHPMailer work under CentOS. Mail work just fine under Windows with XAMPP but I always get this error under Linux.

SMTP服务器是在端口25上侦听的Lotus Domino,CentOS机器根本没有防火墙,奇怪的是,即使mail()也不起作用.它什么也不返回(而在Windows上则返回1).如果我通过CentOS服务器通过telnet发送电子邮件,则可以正常工作,因此我认为这不是网络问题.它必须与PHP相关,但我不知道如何.

The SMTP server is a Lotus Domino listening on port 25, CentOS machine has NO firewall at all and the strange thing is that even mail() does not work. It returns nothing (while on Windows returns 1). If I send an email through telnet via CentOS server it works just fine so I don't think it is a network problem. It must be related to PHP but I don't know how.

<?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)上有效.

Just to clarify the code above works on XAMPP (Windows).

我在PHPMailer上调试了错误,并且这里发生了错误(class.smtp.php方法Connect()):

I debugged the error on PHPMailer and error happens here (class.smtp.php method 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 ...

It looks like it can't open the Socket...

更新:使用$ mail-> SMTPDebug = 2;正如Alvaro所建议的那样,产生了以下输出:

UPDATE: Using $mail->SMTPDebug = 2; as suggested by Alvaro produced this output:

SMTP->错误:无法连接到服务器:权限被拒绝(13)

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

推荐答案

您可以使用SMTPDebug属性启用调试模式,例如:

You can enable debug mode with the SMTPDebug property, e.g.:

$mail = new PHPMailer();
// 1 = errors and messages
// 2 = messages only
$mail->SMTPDebug  = 2;

错误消息将回显到屏幕上.

Error messages will be echoed to screen.

更新:

使用 fsockopen()权限被拒绝错误消息表明用户PHP正在运行如不允许打开插座.如果您仔细检查了是否没有防火墙,则可能是

A permission denied error message using fsockopen() suggests that the user PHP runs as is not allowed to open a socket. If you'd double-checked that there's no firewall, it's possible that's a SELinux problem :-?

这篇关于无法连接到SMTP主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆