Skip to content

Instantly share code, notes, and snippets.

@onubadev
Last active September 30, 2020 14:22
Show Gist options
  • Save onubadev/56de1c46d75436f3e267e64c261429aa to your computer and use it in GitHub Desktop.
Save onubadev/56de1c46d75436f3e267e64c261429aa to your computer and use it in GitHub Desktop.
Sending SMTP Email with Codeigniter 3 over Office365
/*
Minimun test code for successful email sending over SMTP with Office 365
Things to double-check:
- openssl php extension must be enabled in the server
- host set to smtp.office365.com, not the old aliases
- Port 587
- newline configuration: explicit to "\r\n"
*/
//In your Controller code:
$config = [
'protocol' => 'smtp',
'smtp_host' => 'smtp.office365.com',
'smtp_user' => 'YOUR_EMAIL',
'smtp_pass' => 'YOUR_PASSWORD',
'smtp_crypto' => 'tls',
'newline' => "\r\n", //REQUIRED! Notice the double quotes!
'smtp_port' => 587,
'mailtype' => 'html'
];
$this->load->library('email', $config);
$this->email->from('YOUR_FROM_EMAIL');
$this->email->to('TEST_EMAIL');
$this->email->subject('Test');
$this->email->message('SMTP sending test');
$sent = $this->email->send();
if ($sent)
{
echo 'OK';
} else {
echo $this->email->print_debugger();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment