diff options
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r-- | system/libraries/Email.php | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 997757b0a..daa38484b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -96,6 +96,13 @@ class CI_Email { public $smtp_timeout = 5; /** + * SMTP persistent connection + * + * @var bool + */ + public $smtp_keepalive = FALSE; + + /** * SMTP Encryption * * @var string NULL, 'tls' or 'ssl' @@ -403,6 +410,21 @@ class CI_Email { // -------------------------------------------------------------------- /** + * Destructor - Releases Resources + * + * @return void + */ + public function __destruct() + { + if (is_resource($this->_smtp_connect)) + { + $this->_send_command('quit'); + } + } + + // -------------------------------------------------------------------- + + /** * Initialize preferences * * @param array @@ -1183,8 +1205,11 @@ class CI_Email { { if ($this->protocol === 'mail') { - $this->_subject = $this->_headers['Subject']; - unset($this->_headers['Subject']); + if (isset($this->_headers['Subject'])) + { + $this->_subject = $this->_headers['Subject']; + unset($this->_headers['Subject']); + } } reset($this->_headers); @@ -1824,7 +1849,15 @@ class CI_Email { return FALSE; } - $this->_send_command('quit'); + if ($this->smtp_keepalive) + { + $this->_send_command('reset'); + } + else + { + $this->_send_command('quit'); + } + return TRUE; } @@ -1837,6 +1870,11 @@ class CI_Email { */ protected function _smtp_connect() { + if (is_resource($this->_smtp_connect)) + { + return TRUE; + } + $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, @@ -1851,6 +1889,7 @@ class CI_Email { return FALSE; } + stream_set_timeout($this->_smtp_connect, $this->smtp_timeout); $this->_set_error_message($this->_get_smtp_data()); if ($this->smtp_crypto === 'tls') @@ -1924,6 +1963,11 @@ class CI_Email { $this->_send_data('DATA'); $resp = 354; break; + case 'reset': + + $this->_send_data('RSET'); + $resp = 250; + break; case 'quit' : $this->_send_data('QUIT'); @@ -1973,6 +2017,11 @@ class CI_Email { $reply = $this->_get_smtp_data(); + if (strpos($reply, '503') !== 0) // Already authenticated + { + return TRUE; + } + if (strpos($reply, '334') !== 0) { $this->_set_error_message('lang:email_failed_smtp_login', $reply); |