Send email using HTML templates in Codeigniter

Send email using HTML templates in Codeigniter

How to Stop mail in spam in codegniter. This post explains how to send email using HTML templates in Codeigniter, how to send mails using HTML content and using phpmailer and gmail. Now we learn how to send mails in Codeigniter.
By follow the below steps we can implement it.Send email using HTML templates in Codeigniter.

Step 1: Create HTML file with suits to your template.

Path : /application/views/emails/mail_view.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Phpcodehub - Codeigniter mail templates</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div>
   <div style="font-size: 26px;font-weight: 700;letter-spacing: -0.02em;line-height: 32px;color: #41637e;font-family: sans-serif;text-align: center" align="center" id="emb-email-header"><img style="border: 0;-ms-interpolation-mode: bicubic;display: block;Margin-left: auto;Margin-right: auto;max-width: 152px" src="http://www.anil2u.info/wp-content/uploads/2013/09/anil-kumar-panigrahi-blog.png" alt="" width="152" height="108"></div>
<p style="Margin-top: 0;color: #565656;font-family: Georgia,serif;font-size: 16px;line-height: 25px;Margin-bottom: 25px">Hey Phpcodehub,</p>
<p style="Margin-top: 0;color: #565656;font-family: Georgia,serif;font-size: 16px;line-height: 25px;Margin-bottom: 25px"> I am  Phpcodehub , the mail send with html and This is mail demo of How to send email using HTML templates in Codeigniter </p>
</div>
</body>
</html>
Step 2: Controller or function method to send mails

Path : /application/controllers/sendmails.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sendmails extends CI_Controller {

    public function htmlmail(){
        $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);
    $this->email->set_newline("\r\n");
   
        $this->email->from('your mail id', 'Anil Labs');
        $data = array(
             'userName'=> 'Anil Kumar Panigrahi'
                 );
        $this->email->to($userEmail);  // replace it with receiver mail id
    $this->email->subject($subject); // replace it with relevant subject
   
        $body = $this->load->view('emails/mail_view.php',$data,TRUE);
    $this->email->message($body);  
        $this->email->send();
    }
       
}

?>
Step 3: Call the controller method in as per your requirement.

http://[domain name]/Sendmails/htmlmail

Share Button

About admin

Leave a Reply

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

*

Author: pramod kumar kumawat Mob: 9269727062
Free WordPress Themes - Download High-quality Templates