Send email using HTML email template in Codeigniter - Manoj Patial

Send email using HTML email template in Codeigniter

SQL Joins Tutorial
May 24, 2018
3 Best WordPress SEO Plugins
January 16, 2019

Using HTML email template for send email in Codeigniter

In this article you’ll learn how to use email template with dynamic variables for send email to user after signup using Codeigniter email library.

Step 1: Create email message template
First of all create a PHP file in /application/views/emails/ folder which contains your email message with HTML code. In this example I am creating a file with name new_user.php.

<!DOCTYPE html>
<meta charset=”utf-8″ />
<title>Codeigniter email template</title>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″ />

<table bgcolor=”#ececec” style=”border-bottom:1px solid #e0e0e0;width: 100%;margin:0px;”>
<td style=”display:block!important;max-width:600px!important;margin:0 auto!important;clear:both!important;”>
<div style=”padding:15px;max-width:600px;margin:0 auto;display:block;”>
<table bgcolor=”#29BAB2″>
<td><img src=”” /></td>
<table style=”width: 100%;”>
<td style=”display:block!important;max-width:600px!important;clear:both!important;margin:0 auto;” bgcolor=”#FFFFFF” align=”center”>
<div style=”padding:15px;max-width:600px;display:block;margin:0 auto;”>
<td style=”font-family: Open Sans,arial,sans-serif; font-size:16px;”>
<h3 style=”font-family: Open Sans,arial,sans-serif; font-size:22px;margin-bottom:10px;”>Dear {name}</h3>
<p style=”font-family: Open Sans,arial,sans-serif; font-size: 16px;margin-bottom:20px;”>Thanks for signing up to</p>
<p style=”font-family: Open Sans,arial,sans-serif; font-size: 16px;margin-bottom:20px;”>Please find your login details below</p>
<p style=”margin-bottom: 10px;line-height:1.6;font-family: Open Sans,arial,sans-serif; font-size: 16px;”>
Url: {URL}<br/>
Login Email: {user_name}<br/>
Password: {password}<br/>
<p style=”margin-bottom: 10px;line-height:1.6;font-family: Open Sans,arial,sans-serif; font-size: 16px;”>
Thanks & Regards,<br/>Manoj Patial<br/></p>

Step 2: Controller method for send email to user

In controller method we’ll see how to call template and assign value to variables set in email template.

public function htmlmail(){

		//setup SMTP configurion
		$config = Array(    
		  'protocol' => 'sendmail',
		  'smtp_host' => 'your domain SMTP host',
		  'smtp_port' => 25,
		  'smtp_user' => 'SMTP Username',
		  'smtp_pass' => 'SMTP Password',
		  'smtp_timeout' => '4',
		  'mailtype' => 'html',
		  'charset' => 'iso-8859-1'

		$this->load->library('email', $config); // Load email template
		$this->email->from('your mail id', 'Anil Labs');

		$data = array(
			'name'=> 'Manoj Patil',
			'URL'=> '',
			'user_name'=> 'manojpatil',
			'password'=> 'welcome',


		$this->email->to($user_email); // replace it with receiver email id
		$this->email->subject($subject); // replace it with email subject
		$message = $this->load->view('emails/new_user.php',$data,TRUE);



This method can be call when user signup with website.

3.7 3 votes
Article Rating
Manoj Patial
Manoj Patial
I am Manoj Patial, a website developer from India, I have more than 10 years of experience in website development. I developed more than 200+ website using Drupal, WordPress, PHP, Codeigniter, shopify, HubSpot and other CMS/PHP frameworks.
Notify of
Inline Feedbacks
View all comments

Pin It on Pinterest

Would love your thoughts, please comment.x