diff --git a/changelog.md b/changelog.md index 50366b43..7c8f8f2a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # PHPMailer Change Log +## WIP +* Split SMTP connection into two separate methods + ## Version 6.1.6 (May 27th, 2020) * **SECURITY** Fix insufficient output escaping bug in file attachment names. CVE-2020-13625. Reported by Elar Lang of Clarified Security. * Correct Armenian ISO language code from `am` to `hy`, add mapping for fallback diff --git a/src/SMTP.php b/src/SMTP.php index b9bc3f88..99d33035 100644 --- a/src/SMTP.php +++ b/src/SMTP.php @@ -332,17 +332,13 @@ class SMTP $this->smtp_conn = $this->getSMTPConnection($host, $port, $timeout, $options); - $this->edebug('Connection: opened', self::DEBUG_CONNECTION); - // SMTP server can take longer to respond, give longer timeout for first read - // Windows does not have support for this timeout function - if (strpos(PHP_OS, 'WIN') !== 0) { - $max = (int) ini_get('max_execution_time'); - // Don't bother if unlimited - if (0 !== $max && $timeout > $max) { - @set_time_limit($timeout); - } - stream_set_timeout($this->smtp_conn, $timeout, 0); + if ($this->smtp_conn === false) { + //Error info already set inside `getSMTPConnection()` + return false; } + + $this->edebug('Connection: opened', self::DEBUG_CONNECTION); + // Get any announcement $announce = $this->get_lines(); $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); @@ -417,6 +413,17 @@ class SMTP return false; } + // SMTP server can take longer to respond, give longer timeout for first read + // Windows does not have support for this timeout function + if (strpos(PHP_OS, 'WIN') !== 0) { + $max = (int)ini_get('max_execution_time'); + // Don't bother if unlimited + if (0 !== $max && $timeout > $max) { + @set_time_limit($timeout); + } + stream_set_timeout($connection, $timeout, 0); + } + return $connection; }