JonJon2244
JonJon2244

Reputation: 75

PhpMailer able to send mail from Windows but not 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 = "[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;
    }
?>

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: [email protected] : 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?

Upvotes: 1

Views: 2243

Answers (1)

Tim
Tim

Reputation: 699

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.

Upvotes: 2

Related Questions