You are here: Home » Others » Codeigniter » Mail in codeigniter

Mail in codeigniter

24 Flares 24 Flares ×

To use email in codeigniter, use below code, first load email library by using $this->load->library(’email’);.
After it define to,from,subject and message, you can also use cc and bcc. At end use $this->email->send(); to send mail.

$this->load->library('email');

$this->email->from('from@example.com', 'Your Name');
$this->email->to('to@example.com');
$this->email->cc('cc@another-example.com');
$this->email->bcc('bcc@their-example.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();

To debug mail use echo $this->email->print_debugger();
You can set name of sender as $this->email->from(‘you@example.com’, ‘Your Name’);
For repply use $this->email->reply_to(‘you@example.com’, ‘Your Name’);

To create multiple recipient address use
$list = array(‘one@example.com’, ‘two@example.com’, ‘three@example.com’);

$this->email->to($list); Same will be use for cc and bcc.
Use $this->email->clear(); to clear all value to an empty.

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top
24 Flares Twitter 0 Facebook 0 Google+ 0 StumbleUpon 7 Pin It Share 8 LinkedIn 9 24 Flares ×