Last active
September 30, 2020 14:22
-
-
Save onubadev/56de1c46d75436f3e267e64c261429aa to your computer and use it in GitHub Desktop.
Sending SMTP Email with Codeigniter 3 over Office365
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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