Cannot send email via PHPMailer: Could not connect to SMTP host

Created:

2016-12-12 03:42:56 UTC

Modified:

2017-08-10 12:32:33 UTC

0

Was this article helpful?


Have more questions?

Submit a request

Cannot send email via PHPMailer: Could not connect to SMTP host

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux

Symptoms

Cannot send email via PHPMailer :

  • Sending email via SMTP method fails with error:

    HTTP/1.1 200 OK

    FAIL: SMTP Error: Could not connect to SMTP host.
    SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Error: Could not connect to SMTP host.
  • /var/www/vhosts/example.com/public_html/mail.php contains strings like the following:

    if ( strpos($hostname, 'cpnl') === FALSE ) //if not cPanel
    $mail->Host = 'relay-hosting.externalserver.loc';

Cause

mail.php misconfiguration. mail.php contains HTML code for mailer web interface and php code for mail sending. Due to the fact that hostname is not cpln , $mail variable is set to relay-hosting.externalserver.loc and the connection to SMTP server becomes impossible.

Resolution

Correct /var/www/vhosts/example.com/public_html/mail.php as follows:

$mail->IsSMTP();
if ( strpos($hostname, 'cpnl') === FALSE ) //if not cPanel
# $mail->Host = 'relay-hosting.externalserver.loc'; - <------
$mail->Host = 'localhost'; + <------
else
$mail->Host = 'localhost';

Note: mail.php and its path may vary.

Have more questions? Submit a request
Please sign in to leave a comment.