• How to send email using HTML templates in Codeigniter


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

    Path : /application/views/email_template.php
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>Shikha- Codeigniter mail templates</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    </head>
    <body>
    <div>
       <div style="font-size: 36px;font-weight: 700;letter-spacing: -0.02em;line-height: 32px;color: red;font-family: sans-serif;text-align: center" align="center" id="emb-email-header">HTML TEMPLATE</div>
    <p style="Margin-top: 0;color: #565656;font-family: Georgia,serif;font-size: 16px;line-height: 25px;Margin-bottom: 25px">Hey <?php echo $userName;?>,</p> 
    <p style="Margin-top: 0;color: #565656;font-family: Georgia,serif;font-size: 16px;line-height: 25px;Margin-bottom: 25px"> This is mail demo of How to send email using HTML templates in Codeigniter </p>
    </div>
    </body>
    </html>

    Step 2: Controller 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(){
         
            $this->load->library('email');
             $config = array (
                      'mailtype' => 'html',
                      'charset'  => 'utf-8',
                      'priority' => '1'
                       );
            $this->email->initialize($config);
        $this->email->set_newline("\r\n");
        
            $this->email->from('your mail id', 'Shikha Labs');
            $data = array(
                 'userName'=> 'Shikha Pathak'
                     );
            $this->email->to($userEmail);  // replace it with receiver mail id
        $this->email->subject($subject); // replace it with relevant subject 
        
            $body = $this->load->view('email_template.php',$data,TRUE);
        $this->email->message($body);   
            $this->email->send();
        }
           
    }
    Just replace your username , password and mail-ids and use it as HTML templates for sending mails in Codeigniter

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

    http://[domain name]/Sendmails/htmlmail
  • 6 comments:

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari