diff --git a/inc/mailhandlers/smtp.php b/inc/mailhandlers/smtp.php index f68e9c629b..764ebda3db 100644 --- a/inc/mailhandlers/smtp.php +++ b/inc/mailhandlers/smtp.php @@ -94,6 +94,13 @@ class SmtpMail extends MailHandler */ public $secure_port = 465; + /** + * Whether to use a TLS connection. + * + * @var boolean + */ + public $use_tls = false; + /** * SMTP host. * @@ -140,7 +147,7 @@ function __construct() $protocol = 'ssl://'; break; case MYBB_TLS: - $protocol = 'tls://'; + $this->use_tls = true; break; } @@ -274,6 +281,22 @@ function connect() return false; } + if($this->use_tls) + { + $data = $this->send_data('STARTTLS', '220'); + if(!$data) + { + $this->fatal_error("Couldn't switch SMTP to TLS"); + return false; + } + $data = stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + if(!$data) + { + $this->fatal_error("Couldn't switch socket to TLS"); + return false; + } + } + if(!empty($this->username) && !empty($this->password)) { $data = $this->send_data('EHLO ' . $this->helo, '250');