This post is about CodeIgniter Email Class, Sending Emails in Codeigniter App is not a tedious Task,it is very simple and easy with few lines of code, you can set config options on fly, or you can set config options of email library globally(webRoot/applications/config/email.php
)
CodeIgniter’s Email Class features:
- Multiple Protocols: Mail, Sendmail, and SMTP
- Multiple recipients
- CC and BCCs
- HTML or Plaintext email
- Attachments
- Word wrapping
- Priorities
- BCC Batch Mode, enabling large email lists to be broken into small BCC batches.
- Email Debugging tools
for more information visit Codeigniter official Docs http://ellislab.com/codeigniter/user-guide/libraries/email.html
Now I will explain how to send email using PHP and CodeIgniter Framework,you must load email library in order to send emails.
How to Load Email Library
$this->load->library('email');
How to send a HTML emails
// load email library $this->load->library('email'); // from address $this->email->from('[email protected]', 'Your Name'); $this->email->to('[email protected]'); // to Email address $this->email->cc('[email protected]'); // cc Email address (optional) $this->email->bcc('[email protected]'); // BCC Email Address (optional) $this->email->subject('Email Test'); // email Subject $this->email->message('Testing the email class.'); // email Body or Message $this->email->send(); // send Email
How to send HTML mail
$message = $this->load->view('emails_view',$dataToView,TRUE); $this->load->library('email'); // from address $this->email->from('[email protected]', 'Your Name'); $this->email->to('[email protected]'); // to Email address $this->email->cc('[email protected]'); // cc Email address (optional) $this->email->bcc('[email protected]'); // BCC Email Address (optional) $this->email->subject('Email Test'); // email Subject $this->email->message($message); // email Body or Message $this->email->send(); // send Email
CodeIgniter Email errors and debugging
print_r($this->email->print_debugger(), true);
print_r($this->email->print_debugger(), true);