Codeigniter 2.20 – Sending E-mail using codeigniter

Back to CodeIgniter Tutorials

In CodeIgniter, sending e-mail is a simple process. First the library is loaded. Then the user provides e-mail related data. Finally, the E-mail is sent. Here is how E-mail is sent using a Controller in CodeIgniter

  1. Load the E-mail library of CodeIgniter
    $this->load->library('email');
  2. Provide set of characters that are to be permitted in the E-mail address.
    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@&\-!';
  3. Initialize the type of e-mail as html (options text or html)
    $this->email->initialize(array('mailtype' => 'html'));
  4. Provide Sender’s E-mail address
    $this->email->from('EMAIL ADDRESS OF SENDER', 'NAME OF SENDER');
  5. Provide Receiver’s E-mail Address
    $this->email->to($RECEIVER_EMAIL_ADDRESS);
  6. Provide BCC E-mail address
    $this->email->bcc('BCC_PERSON@codeonion.com');
  7. Provide Subject of the E-mail
    $this->email->subject('THIS STRING IS THE SUBJECT OF EMAIL');
  8. Provide Body of the E-mail.
    $this->email->message('Hello my E-mail Receiver. ');
  9. Send the E-mail!
    $this->email->send();

Following is the complete code of the above process.

$this->load->library('email');
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@&\-!';
$this->email->initialize(array('mailtype' => 'html'));
$this->email->from('EMAIL ADDRESS OF SENDER', 'NAME OF SENDER');
$this->email->to($RECEIVER_EMAIL_ADDRESS);
$this->email->bcc('BCC_PERSON@codeonion.com');
$this->email->subject('THIS STRING IS THE SUBJECT OF EMAIL');
$this->email->message('Hello my E-mail Receiver. ');
$this->email->send();

Let me know in comments if there is something that you would like to know. And do like an share.

Back to CodeIgniter Tutorials

One thought on “Codeigniter 2.20 – Sending E-mail using codeigniter

Leave a Reply

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