Added TLS and SSL support to Email library. Fixes issue #171
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index c8cb854..648bb6b 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -36,6 +36,7 @@
 	var	$smtp_pass		= "";		// SMTP Password
 	var	$smtp_port		= "25";		// SMTP Port
 	var	$smtp_timeout	= 5;		// SMTP Timeout in seconds
+	var	$smtp_crypto	= "";		// SMTP Encryption. Can be null, tls or ssl.
 	var	$wordwrap		= TRUE;		// TRUE/FALSE  Turns word-wrap on/off
 	var	$wrapchars		= "76";		// Number of characters to wrap at.
 	var	$mailtype		= "text";	// text/html  Defines email formatting
@@ -1667,7 +1668,10 @@
 	 */
 	protected function _smtp_connect()
 	{
-		$this->_smtp_connect = fsockopen($this->smtp_host,
+		$ssl = NULL;
+		if ($this->smtp_crypto == 'ssl')
+			$ssl = 'ssl://';
+		$this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
 										$this->smtp_port,
 										$errno,
 										$errstr,
@@ -1680,6 +1684,14 @@
 		}
 
 		$this->_set_error_message($this->_get_smtp_data());
+
+		if ($this->smtp_crypto == 'tls')
+		{
+			$this->_send_command('hello');
+			$this->_send_command('starttls');
+			stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
+		}
+
 		return $this->_send_command('hello');
 	}
 
@@ -1706,6 +1718,12 @@
 
 						$resp = 250;
 			break;
+			case 'starttls'	:
+
+						$this->_send_data('STARTTLS');
+
+						$resp = 220;
+			break;
 			case 'from' :
 
 						$this->_send_data('MAIL FROM:<'.$data.'>');