PhpMailer能够从Windows而不是CentOS发送邮件

时间:2013-03-25 01:35:31

标签: apache centos phpmailer php

我的Windows上有Apache w / php用于测试目的。 我的生产CentOS 6.4服务器上也有Apache w / php。

我可以使用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 个答案:

答案 0 :(得分:2)

我从消息中理解的是

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

如果我是你,我会按顺序尝试以下事项:

  1. ping mail.example.com以确保我可以解析该域名。
  2. Telnet到mail.example.com的第25个端口,以确保我的服务器可以连接到邮件服务器。
  3. 使用telnet或其他邮件客户端测试邮件服务器。
  4. 你应该陷入其中一个步骤,它应该有助于解决这个问题。

相关问题