dptiq46022 2013-03-25 01:35
浏览 92
已采纳

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

I have Apache w/ php on my windows for testing purpose. I also have Apache w/ php on my production CentOS 6.4 server.

I am able to perfectly send an email on my windows server using PHPMailer. However, I am not able to send it on my centos server.

This is my code:

    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;
    }
?>

Once again, it works perfectly on my Windows Apachhe. However, the following error occures on 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

I have tested the firewall and I don't think that's the issue. I even turned it off completely(for testing) and it was still giving me that error.

I have openssl installed and enabled on my php.

Any ideas?

  • 写回答

1条回答 默认 最新

  • douyi2798 2013-03-25 03:18
    关注

    What I understand from the message is

    • that your client can't reach to the mail server or
    • the mail server closing connection after a while, before the client sent all of the commands.

    If I were you, I would try the followings in order:

    1. Ping the mail.example.com to be sure that I can resolve the domain.
    2. Telnet to mail.example.com's 25th port to be sure that my server can connect to mail server.
    3. Test the mail server by using telnet or another mail client.

    You should get stuck at one of those steps and it should help to solve that problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),如何通过环岛的原理及完整代码
  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?