【发布时间】:2015-04-02 14:04:08
【问题描述】:
我一直在 CentOS 6.6 机器上设置 Wordpress,我对这些东西还很陌生。全新安装所有最新版本的 httpd、php、mySQL 和 Wordpress。
现在一切正常,除了使用 SMTP 发送电子邮件。我在 Wordpress 中安装了几个插件来配置 SMTP,但是发送测试电子邮件总是会导致类似 SMTP connect() failed 的错误。我已经非常确定我的凭据没有问题。
从命令行我尝试了这些:
telnet smtp.gmail.com 25
和
openssl s_client -connect smtp.gmail.com:465
他们两个都可以毫无问题地将我连接到 gmail 的 smtp。由于 Wordpress 不允许连接的持续错误,最后我决定将 Wordpress 排除在外,并在我的服务器上创建了一个测试 php 文件,其中包含以下代码,该代码为所有端口返回“无响应”:
<?php
$host = 'smtp.gmail.com';
$ports = array(25, 465, 587);
foreach ($ports as $port)
{
$connection = @fsockopen($host, $port);
if (is_resource($connection))
{
echo '<h2>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</h2>' . "\n";
fclose($connection);
}
else
{
echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\n";
}
}
将上面的 php 脚本更改为 www.gmail.com 并巧妙地添加端口 80 和 443 会显示 80 和 443 是打开的,其余的是关闭的(这很有意义,因为我现在正在查看 www 服务器),所以脚本似乎工作正常。
我猜这一定是 PHP 本身的问题,不允许我通过任何 SMTP 端口(因为我可以从 cmdline 远程登录到这些端口)
我无法弄清楚 PHP 中的问题可能是什么。任何人都知道如何解决这个问题?
【问题讨论】:
-
发现每次刷新php测试页面,audit.log都会有新的条目进入:
-
type=SYSCALL msg=audit(1422965981.489:1703803): arch=c000003e syscall=42 成功=没有退出=-13 a0=1f a1=7f12c44a0ef8 a2=10 a3=7f12c005514c items=0 ppid= 53588 pid=53590 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=492 comm="httpd" exe="/usr/ sbin/httpd" subj=unconfined_u:system_r:httpd_t:s0 key=(null) type=AVC msg=audit(1422965981.489:1703804): avc: denied { name_connect } for pid=53590 comm="httpd" dest=465 scontext= unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:smtp_port_t:s0 tclass=tcp_socket
标签: php wordpress apache smtp centos6