diff --git a/changelog.md b/changelog.md index 241e1df8..b3174b57 100644 --- a/changelog.md +++ b/changelog.md @@ -55,6 +55,7 @@ This is a major update that breaks backwards compatibility. * Now checks for invalid host strings when sending via SMTP. * Include timestamps in HTML-format debug output * More reliable folding of message headers +* Inject your own SMTP implementation via `setSMTPInstance()` instead of having to subclass and override `getSMTPInstance()`. ## Version 5.2.23 (March 15th 2017) * Improve trapping of TLS errors during connection so that they don't cause warnings, and are reported better in debug output diff --git a/src/PHPMailer.php b/src/PHPMailer.php index 90829622..296603a6 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -1587,7 +1587,8 @@ class PHPMailer /** * Get an instance to use for SMTP operations. - * Override this function to load your own SMTP implementation + * Override this function to load your own SMTP implementation, + * or set one with setSMTPInstance. * * @return SMTP */ @@ -1599,6 +1600,18 @@ class PHPMailer return $this->smtp; } + /** + * Provide an instance to use for SMTP operations. + * + * @param SMTP $smtp + * @return SMTP + */ + public function setSMTPInstance(SMTP $smtp) + { + $this->smtp = $smtp; + return $this->smtp; + } + /** * Send mail via SMTP. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.