Handle early connection errors, see #2211

This commit is contained in:
Marcus Bointon 2020-12-04 15:15:20 +01:00
parent 338b5597ac
commit 5050b6012f
No known key found for this signature in database
GPG Key ID: DE31CD6EB646AA24
2 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,8 @@
# PHPMailer Change Log
## WIP
* Handle early connection errors such as 421
## Version 6.2.0
* PHP 8.0 compatibility, many thanks to @jrf_nl!
* Switch from PHP CS Fixer to PHP CodeSniffer for coding standards

View File

@ -343,8 +343,20 @@ class SMTP
// Get any announcement
$this->last_reply = $this->get_lines();
$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
return true;
$responseCode = (int)substr($this->last_reply, 0, 3);
if ($responseCode === 220) {
return true;
}
//Anything other than a 220 response means something went wrong
//RFC 5321 says the server will wait for us to send a QUIT in response to a 554 error
//https://tools.ietf.org/html/rfc5321#section-3.1
if ($responseCode === 554) {
$this->quit();
}
//This will handle 421 responses which may not wait for a QUIT (e.g. if the server is being shut down)
$this->edebug('Connection: closing due to error', self::DEBUG_CONNECTION);
$this->close();
return false;
}
/**