Send HTML Email With Image In CodeIgniter.

Sending an Email is a very common functionality in any web application. For example, we can send welcome Email when user register on our website, send a newsletter Email, sending an invoice, sending a birthday wishes. We can send either text mail or html Email. For better user experience we should prefer html Email. So In this post we will learn how we can send html Email with image in CodeIgniter.

Sending an Email in CodeIgniter is much easier because it is robust MVC framework so it has an inbuilt Email library to sending email in application. We can send text Email as well as HTML Email using it’s inbuilt Email library.

It’s robust Email class supports the following features:

Multiple Protocols: Mail, Sendmail, and SMTP.

TLS and SSL Encryption for SMTP.

Multiple recipients.

CC and BCCs.

HTML or Plaintext email.


Word wrapping.


BCC Batch Mode, enabling large email lists to be broken into small BCC batches.

Email Debugging tools.

Below are the steps to send HTML Email with image in CodeIgniter.

Load The Email Library First.


Create Controller.

defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
class HtmlEmail extends CI_Controller {

public function index(){

$config[‘mailtype’] = ‘html’;
$data = array(‘name’ => ‘PHPFOREVER’);
$from_email = “[email protected]”;
$to_email = ‘[email protected]’;
$this->email->from($from_email, ‘PHPFOREVER’);
$this->email->set_header(‘Content-Type’, ‘text/html’);
$this->email->subject(‘Email Test’);
echo “Mail Sent”;
echo “Error”;

Create View.

<style type=’text/css’>
body {font-family: Verdana, Geneva, sans-serif}
p {font-weight:bold}
<h3>Hi <?php echo $name;?>,</h3>
<h3>Welcome to CI HTML Email Tutorial.</h3>
<img src='<?=base_url()?>/public/Desert.jpg’>
<p>In this post we will learn, how we can send HTML email in codeigniter.</p>

Send Email To Multiple Recipients.

$toarray = array(‘[email protected]’,’[email protected]’,’[email protected]’,
[email protected]’);

Set The CC And BCC.

$this->email->cc(‘[email protected]’);
$this->email->bcc(‘[email protected]’);

Rest API In Codeigniter – 3. Codeigniter – Autocomplete Search using Typeahead

The post Send HTML Email With Image In CodeIgniter. appeared first on PHPFOREVER.

Flatlogic Admin Templates banner

Leave a Reply

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