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

By codeonion

Codeonion contributes to the honorable mission of “helping people learn and earn online”. Whether your day job is creative or not, life is better when you learn and apply creative skills regularly. To do this is satisfying in its own right and a practical investment in your future.

1 comment

Leave a Reply to Jennifer Nicol Colwell Cancel reply

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