In this tutorial, we’ll show the most used email features for the web project. Using our sample code you can send a text email, HTML email, and email with an attachment in Codeigniter.
Code
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to("demo@gmail.com");
$this->email->from("from@gmail.com");
$this->email->subject("Test");
$this->email->message("Type Your Message");
$this->email->attach(base_url().'/assets/pdf_invoice/'.$pdfname.'');
$this->email->send();