我的 Windows 上有 Apache w/php 用于测试目的。 我的生产 CentOS 6.4 服务器上也有带 php 的 Apache。
我可以使用 PHPMailer 在我的 Windows 服务器上完美地发送电子邮件。 但是,我无法在我的 centos 服务器上发送它。
这是我的代码:
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = 'mail.example.com';
$mail->Port = 25;
$mail->Username = "mail-daemon@example.com";
$mail->Password = "secret";
$mail->SMTPSecure = 'tls';
$mail->SetFrom('mail-daemon@example.com', "$name");
$mail->Subject = "$subj";
$mail->Body = $body;
$mail->AddAddress("Support@example.com");
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo "We're sorry, however, an error has occurred. You may manually e-mail us at support@example.com.";
return false;
} else {
echo "Thanks! Your message was successfully sent.";
return true;
}
?>
再一次,它在我的 Windows Apachhe 上完美运行。 但是在CentOS上出现如下错误。
SMTP -> ERROR: Failed to connect to server: Connection timed out (110) <br />The following From address failed: mail-daemon@example.com : Called Mail() without being connected
我已经测试了防火墙,我认为这不是问题所在。我什至完全关闭它(为了测试),它仍然给我那个错误。
我在我的 php 上安装并启用了 openssl。
有什么想法吗?
最佳答案
我从消息中了解到的是
- 您的客户端无法访问邮件服务器或
- 在客户端发送所有命令之前,邮件服务器在一段时间后关闭连接。
如果我是你,我会按顺序尝试以下操作:
- Ping mail.example.com 以确保我可以解析域。
- Telnet 到 mail.example.com 的第 25 个端口以确保我的服务器可以连接到邮件服务器。
- 使用 telnet 或其他邮件客户端测试邮件服务器。
您应该卡在这些步骤之一,它应该有助于解决该问题。
关于apache - PhpMailer 能够从 Windows 但不能从 CentOS 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606356/