I knew CodeIgniter could send  out emails using its own Email class which supports three types: mail, sendmail & smtp

I initially configured the controller using following config, which failed, with error message “Severity: Warning –> stream_socket_enable_crypto(): SSL: crypto enabling timeout

$config = array (
‘protocol’ => ‘smtp’,
‘mailtype’ => ‘html’,
‘charset’ => ‘utf-8’,
‘crlf’ => “rn”,
‘priority’ => 3,
‘smtp_host’ => ‘smtp.office365.com’,
‘smtp_port’ => ‘587’,
‘smtp_crypto’ => ‘tls’,
‘smtp_user’ => ‘yourOffice365EmailAddress’,
‘smtp_pass’ =>’yourPassword’,
‘smtp_timeout’ => 5
);
$this->email->initialize($config);

Then I switched to using protocol “sendmail”, after which the email could be received by Gmail but not the Office365 account which was really odd. When I checked email header in Gmail(show Original), I found there was sentence saying something like the domain sending this email is not considered permitted sender( xxxx does not designate xxx.xxx.xxx.xxx (ip address) as permitted sender). I believed this was the reason why the Office365 didn’t (or maybe refuse) receive such emails.

When I Googled, I found some solutions saying using tls://smtp.office365.com, and I received even more confusing error message such as “Severity: Warning –> fsockopen(): SSL operation failed with code 1”, “SSL routines:SSL3_GET_RECORD:wrong version number”

Googled those error messages turned out taking me even further off the correct track(some article said need OpenSSL while some said need to install email server, etc)

After hours of searching and frustration, I happened to put the following line into config:

‘newline’ => “rn”, //must have for office365!

and boom, Office365 email service worked!

So the only correct solution is the following:

$config = array (
‘protocol’ => ‘smtp’,
‘mailtype’ => ‘html’,
‘charset’ => ‘utf-8’,
‘crlf’ => “rn”,
‘newline’ => “rn”, //must have for office365!
‘priority’ => 3,
‘smtp_host’ => ‘smtp.office365.com’,
‘smtp_port’ => ‘587’,
‘smtp_crypto’ => ‘tls’,
‘smtp_user’ => ‘yourOffice365EmailAddress’,
‘smtp_pass’ =>’yourPassword’,
‘smtp_timeout’ => 5
);

Now going back to CodeIgniter documentation, it does say “Use “rn” to comply with RFC 822” however its default value is “n”. I guess this time we cannot blame Microsoft!

Sending out emails using CodeIgniter from Office365 account

One thought on “Sending out emails using CodeIgniter from Office365 account

  • 03/13/2016 at 5:13 pm
    Permalink

    I would like to thank you for the efforts you’ve put
    in penning this site. I’m hoping to see the same high-grade blog
    posts from you later on as well. In fact, your creative writing abilities
    has inspired me to get my own, personal site now
    😉

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = 4

This site uses Akismet to reduce spam. Learn how your comment data is processed.