Centos – PHPMailer with SSL – CentOS 6.7 VPS – SMTP ERROR: Failed to connect to server: (0)

centosPHPsmtp

I have a CentOS 6.7 VPS and PHPMailer 5.2.14 will not connect to my mail server. I have tried troubleshooting the problem but nothing has solved my issue yet. My PHP is version 5.6.18. The only output I am getting from verbose debug (SMTPDebug = 4), is:

2016-03-06 23:05:40 Connection: opening to ssl://mail.server.com:465, timeout=300, options=array ( )

2016-03-06 23:05:40 SMTP ERROR: Failed to connect to server: (0)

Things I have tried to fix the issue:

  • Disable SELinux (currently is enabled with both http_can_sendmail, http_can_network_connect)
  • Disable Firewall (currently enabled again)
  • Checked that php openssl package is enabled (listed in php -m)
  • Double checked all credentials (no whitespaces, no anything)

Other info:

  • Can connect to my mail server with openssl s_client on port 465
  • PHPmailer can send on port 25 with no SSL

There are many similar posts, however they have all been fixed by the things I have listed above. Any suggestions would be greatly appreciated.

Best Answer

If the mail server uses an invalid or self-signed certificate, you may need to set allow_self_signed true, verify_peer false and verify_peer_name false context options.

I am not a PHPMailer user. I guess you may need to set SMTPOptions attribute. Please, test this piece of code (reference):

$PHPMailer->SMTPOptions = array (
    'ssl' => array (
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
Related Topic