PhpMailer能够从Windows发送邮件,但不能发送邮件

问题描述:

我有用于测试目的的Windows上的Apache w/php。 我的生产CentOS 6.4服务器上也有Apache w/php。PhpMailer能够从Windows发送邮件,但不能发送邮件

我能够使用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 = "[email protected]"; 
    $mail->Password = "secret"; 
    $mail->SMTPSecure = 'tls';  
    $mail->SetFrom('[email protected]', "$name"); 
    $mail->Subject = "$subj"; 
    $mail->Body = $body; 
    $mail->AddAddress("[email protected]"); 
    if(!$mail->Send()) { 
     $error = 'Mail error: '.$mail->ErrorInfo; 
     echo "We're sorry, however, an error has occurred. You may manually e-mail us at [email protected]"; 
     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: [email protected] : Called Mail() without being connected 

我测试过防火墙,我不认为这是问题所在。我甚至完全关闭它(测试),它仍然给我这个错误。

我有openssl安装并启用我的PHP。

任何想法?

我从消息了解什么是

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

如果我是你,我会尝试了以下的顺序:

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

你应该被困在这些步骤之一,它应该有助于解决这个问题。

+0

你好,我只是做了测试,才能够阅读你的文章。 然而,你是对的,我无法telnet到端口25. 我可以telnet mail.example.com 465,但是,我无法telnet mail.example.com 25 我问过我的vps托管提供商,他们说他们没有阻止任何东西,也许它是电子邮件提供商? 我可以在我的其他主机上telnet mail.exmaple.com 25。 – JonJon2244 2013-03-25 03:44:04

+0

您必须连接端口25才能将邮件放入邮件服务器。所以这就是问题所在。一些ISP阻止端口25以防止垃圾邮件。你可以尝试587而不是25. – Tim 2013-03-25 03:46:22

+0

587被拒绝。 465的作品,但是,它导致了我的BB很多错误,所以需要得到检查。 任何一种方式,26作品,而不是25. 所以基本上,解决方案是使用26/465。 也,因为你是唯一一个试图帮助,最好的答案是你的先生。 – JonJon2244 2013-03-25 04:03:47