Take the 2-minute tour ×

I'm trying to use the CodeIgniter Email Class to write a secure SMTP email; either SSL or TLS (preferred). In the past, I've successfully used PHPMailer with Secure Auth and TLS. I believe it was a secure connection. TLS shows up in the email header.

Does CodeIngiters' Email Class support secure SMTP authentication with TLS?

Note, this is not a Gmail question. I'm trying to use it with an MS Exchange Server. I've confirmed the PHPMailer code below functions correctly.

$mail = new PHPMailer(true);
$mail->Host = 'www.domain.com';

$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port     = '25';
$mail->Timeout  = '60';

$mail->Username = 'user@domain.com';
$mail->Password = 'password';

$mail->From     = 'alerts@domain.com';
$mail->FromName = 'Alerts';

$mail->Subject  = 'Test from test email file.';
$mail->MsgHTML('This is just a test.');

// To
$mail->AddAddress('alerts@domain.com', 'Research');
$result = $mail->Send();

With CodeIgniter I've already extended the Email Class (MY_Email.php). The class is a bit big to post here. But, here's the error I keep getting.


array(7) { 
["smtp_host"]=> string(26) "tls://www.domain.com" 
["smtp_port"]=> string(2) "25" 
["smtp_user"]=> string(17) "alerts@domain.com" 
["smtp_pass"]=> string(9) "password" 
["smtp_to_email"]=> string(26) "user@domain.com" 
["smtp_from_email"]=> string(26) "user@domain.com" 
["smtp_from_name"]=> string(24) "Test from Application" 

Error Message:

fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:func(143):reason(267)

Any idea what reason 267 is?

share|improve this question
You can google the error code to learn more or just use PHPMailer inside codeigniter. You can use other PHP libraries next to CI's ones, which might be a good idea if you already have code that is working. –  hakre Oct 10 '11 at 13:50
If you have it working in PHPMailer then I would just include it as a library in CI. I've personally had problems with CI's email class in the past and do the same thing. –  fire Oct 10 '11 at 13:50
add comment

2 Answers

up vote 3 down vote accepted

Found a solution on the CI forums.

Exchange Email Class Patch http://codeigniter.com/forums/viewthread/158882/

It is initiating TLS after SMTP server has been connected.

Worked for me. Jeff

share|improve this answer
add comment

How to diagnose OpenSSL errors:

Look at the error message:

error:1408F10B:SSL routines:func(143):reason(267)

Take the reason code (267) and determine the error:

grep 267 /usr/include/openssl/ssl.h


Read the first hit: http://www.mail-archive.com/openssl-dev@openssl.org/msg02770.html

    Many of SSL clients sends the first CLIENT HELLO with
    ssl2 format (0x80.....) because they don't know what
    version the server supports.
    In this first message, the client sends the version
    he wants to use (3 for SSL3), then the other exchanged
    messages are in the appropriate format SSL3 for V3,
    SSL2 for V2 etc....

    So in your server method configuration you must put:
      SSL_CTX *ctx = SSL_CTX_new (SSLv23_server_method())
    to correctely analyse the first client_hello message
    instead of 
      SSL_CTX *ctx = SSL_CTX_new (SSLv3_server_method())
    which i suppose you did.

Conclusion: the smtp-server uses SSLv3_server_method and therefore needs to be fixed to use SSLv23 instead.

share|improve this answer
According to phpinfo() - Registered Stream Socket Transports: tcp, udp, unix, udg, ssl, sslv3, sslv2, tls. Is there a way of configuring PHP to use SSLV3 for the TLS connection? –  jjwdesign Oct 10 '11 at 14:30
I think you don't understand this properly. However, why don't you just use the PHPMailer class and you're fine? –  hakre Oct 10 '11 at 14:52
add comment

Your Answer


