How to send email with an attachment using Codeigniter

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("[email protected]");
$this->email->from("[email protected]");
$this->email->subject("Test");
$this->email->message("Type Your Message");
$this->email->attach(base_url().'/assets/pdf_invoice/'.$pdfname.'');
$this->email->send();

Leave a Reply

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