Phpmailer: SMTP Error: Could not connect to SMTP host - that used to work in previous versions with the same setup

Created on 12 Jul 2015  路  8Comments  路  Source: PHPMailer/PHPMailer

An older version of PHPMailer (downloaded a month or two ago) used to work flawlessly with this SMTP server. The problem appeared in a recent update of PHPMailer.

I've tried different setups: 1) regular SMTP on port 25, 2) TLS, 3) SSL. All produce the same debug output and my messages can't be sent.

Here's the debug output:

2015-07-12 16:03:00 SERVER -> CLIENT: 220 m-marketing.ru ESMTP CommuniGate Pro 5.2.20
2015-07-12 16:03:00 CLIENT -> SERVER: EHLO limoscanner.com
2015-07-12 16:03:00 SERVER -> CLIENT: 250-m-marketing.ru is pleased to meet you
250-DSN
250-SIZE
250-STARTTLS
250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5
250-ETRN
250-TURN
250-ATRN
250-NO-SOLICITING
250-8BITMIME
250-HELP
250-PIPELINING
250 EHLO
2015-07-12 16:03:00 CLIENT -> SERVER: STARTTLS
2015-07-12 16:03:00 SERVER -> CLIENT: 220 please start a TLS connection
2015-07-12 16:03:00 SMTP Error: Could not connect to SMTP host.
2015-07-12 16:03:00 CLIENT -> SERVER: QUIT
2015-07-12 16:03:00 SERVER -> CLIENT: 
(added from a later log, these lines were cut off by unprintable characters):
2015-07-12 16:34:45 SMTP ERROR: QUIT command failed: 
2015-07-12 16:34:45 SMTP Error: Could not connect to SMTP host.

Most helpful comment

OK, I resolved the issue by myself.

Added:

$mail->SMTPAutoTLS = false;

Looks like in the new version the "SMTPAutoTLS" is enabled by default, I just disabled it.

All 8 comments

I did a debug, the code returns "false" here:

    // Begin encrypted connection
    if (!stream_socket_enable_crypto(
        $this->smtp_conn,
        true,
        STREAM_CRYPTO_METHOD_TLS_CLIENT
    )) {
        return false;
    }

Line 345, class.smtp.php

Maybe if stream_socket_enable_crypto fails like this, PHPMailer should go on using a regular unencrypted connection if the client doesn't require a TLS or SSL?

OK, I resolved the issue by myself.

Added:

$mail->SMTPAutoTLS = false;

Looks like in the new version the "SMTPAutoTLS" is enabled by default, I just disabled it.

where it to add Mr. AlexGnatko.

@AlexGnatko thank you for the solution. I had same error. Solved with your trick. +1

5.2.23 adds better error reporting of TLS problems if you set SMTPDebug = 3. SMTPAutoTLS is on by default as encrypted connections should be used at every opportunity, if the server offers it. Turning it off can work, but is a poor-quality workaround as it's just ignoring that either your client or server is broken.

i'm having trouble in PHPMailer , the error ,
SMTP Error: Could not connect to SMTP host.
what to do??

@coder-avk, please don鈥檛 hijack closed tickets. Use latest version, read the troubleshooting guide.

Was this page helpful?
0 / 5 - 0 ratings