raz*_*z3r 12 php smtp phpmailer
SMTP错误:无法连接到SMTP主机.无法发送消息.
邮件程序错误:SMTP错误:无法连接到SMTP主机.
我似乎找不到让PHPMailer在CentOS下工作的方法.使用XAMPP在Windows下邮件工作正常,但我总是在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";
?>
Run Code Online (Sandbox Code Playgroud)
只是为了澄清上面的代码适用于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;
}
Run Code Online (Sandbox Code Playgroud)
它看起来无法打开Socket ......
更新:使用$ mail-> SMTPDebug = 2; 正如Alvaro所建议的那样输出:
SMTP - >错误:无法连接到服务器:权限被拒绝(13)
小智 37
OS CentOS 6.3
无法发送电子邮件
经过一番研究后发现SELinux阻止了通信
SELinux默认激活并配置.因此SELinux不允许Apache(httpd,phpmailer)使用sendmail功能并进行任何类型的网络连接.
使用getsebool命令,我们可以检查是否允许httpd demon通过网络建立连接并发送电子邮件.
getsebool httpd_can_sendmail
getsebool httpd_can_network_connect
Run Code Online (Sandbox Code Playgroud)
此命令将打开或关闭布尔值.如果关闭,我们可以使用以下设置:
sudo setsebool -P httpd_can_sendmail 1
sudo setsebool -P httpd_can_network_connect 1
Run Code Online (Sandbox Code Playgroud)
现在您可以测试您的php,代码以查看SendMail是否正常工作.
Álv*_*lez 11
您可以使用SMTPDebug属性启用调试模式,例如:
$mail = new PHPMailer();
// 1 = errors and messages
// 2 = messages only
$mail->SMTPDebug = 2;
Run Code Online (Sandbox Code Playgroud)
错误消息将回显到屏幕.
更新:
一个权限被拒绝使用错误消息的fsockopen()认为,PHP运行的用户是不允许打开一个套接字.如果你仔细检查过没有防火墙,那可能是SELinux问题: - ?
| 归档时间: |
|
| 查看次数: |
23820 次 |
| 最近记录: |