apache - PhpMailer 能够从 Windows 但不能从 CentOS 发送邮件

标签 apache centos phpmailer php

我的 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。

有什么想法吗?

最佳答案

我从消息中了解到的是

  • 您的客户端无法访问邮件服务器或
  • 在客户端发送所有命令之前,邮件服务器在一段时间后关闭连接。

如果我是你,我会按顺序尝试以下操作:

  1. Ping mail.example.com 以确保我可以解析域。
  2. Telnet 到 mail.example.com 的第 25 个端口以确保我的服务器可以连接到邮件服务器。
  3. 使用 telnet 或其他邮件客户端测试邮件服务器。

您应该卡在这些步骤之一,它应该有助于解决该问题。

关于apache - PhpMailer 能够从 Windows 但不能从 CentOS 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606356/

相关文章:

PHPMailer 发送带有警告 : This message may not have been sent by: foo@gmail. com 的电子邮件 了解更多 报告网络钓鱼

apache - AWS EC2 t2.micro 框发送 503 错误

在 Ubuntu 上通过 SSL 的 Apache ERR_CONNECTION_REFUSED

centos - 无法在 Centos 6 上安装 RPM

PHP-发送每日电子邮件

PHP:如何保护 .htaccess 中 PHP 文件中的 'plaintext' 密码

apache - 重定向 URL(使用特定的 GET 参数)

java - 如何使用 Apache HttpClient 将参数添加到 HTTP header

Centos7 extras 和 rhel7 extras 丢失包问题

linux - 如何使用 rm -rf 从目录中删除文件?