Asked  1 Year ago    Answers:  5   Viewed   12 times

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 = '';

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

$mail->Username = '';
$mail->Password = 'password';

$mail->From     = '';
$mail->FromName = 'Alerts';

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

// To
$mail->AddAddress('', '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://" 
["smtp_port"]=> string(2) "25" 
["smtp_user"]=> string(17) "" 
["smtp_pass"]=> string(9) "password" 
["smtp_to_email"]=> string(26) "" 
["smtp_from_email"]=> string(26) "" 
["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?



Found a solution on the CI forums.

Exchange Email Class Patch

It is initiating TLS after SMTP server has been connected.

Worked for me. Jeff

Saturday, May 29, 2021
$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
$this->load->library('email', $config);

// Set to, from, message, etc.

$result = $this->email->send();

From the CodeIgniter Forums

Thursday, April 1, 2021

I finally found the solution using socat, Kindly follow these steps :

  1. First of all, you'll need to install socat on the server, you can do that simply using the command below :

    yum install socat
  2. Then run the following socat command that will bind PROXY_IP:PORT with HOST_ESP:PORT :

    socat TCP4-LISTEN:proxy_port,bind=proxy_IP,fork,su=nobody TCP4:host:port,bind=proxy_IP
  3. Then instead of making a send to the ESP through HOST_ESP:PORT you could just make it using PROXY_IP:PORT and socat will do the redirection automatically towards HOST_ESP:PORT using the output of PROXY_IP:PORT.

Hope this helps.

Thursday, April 1, 2021

What version of CI are you using? If it's 2.1.4 then there is a discrepancy in your config array. Try this:

$configs = array(
    'protocol'  =>  'smtp',
    'smtp_host' =>  'ssl://',
    'smtp_user' =>  '',
    'smtp_pass' =>  'PASSWORD',
    'smtp_port' =>  '465'
Thursday, April 1, 2021

It sounds like your DNS server is not resolving Try opening a command prompt on your server, and typing:


Does it resolve? If not, try using a different DNS server (by change /etc/resolve.conf). It does in fact resolve on a server that I tested from.

Thursday, April 1, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :