Wednesday, July 13, 2016

How to send emails with HTML page/template in codeigniter

Codeigniter allows programmers to send HTML file as an email. This helps to send emails using codeigniter in a good formatted and stylish method. Below we have given codes to send HTML pages along with email in codeigniter. Just run it and comment your view below.
codeigniter send email using html template
codeigniter send email using html template

How send emails in codeignter using email templates?

Controller:

public function test_email()
{
        $this->email->set_mailtype("html");
 $this->email->from('noreply@w3schools100.in', 'W3Schools100');
 $this->email->to('receiver@gmail.com');
 $this->email->subject('Subject');
     
 $mail_data['subject'] = 'Email Subject';
 $mail_data['description'] = "Email body contents..Here you can use HTML tables to format your data..And use \n to print date in a new line"

 $message = $this->load->view('email_page', $mail_data, true);
 $this->email->message($message);
 $this->email->send();
} 
View: -> email_page.php

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"></link>
  <style>
    /* Remove the navbar's default rounded borders and increase the bottom margin */ 
    .navbar {
      margin-bottom: 50px;
      border-radius: 0;
    }
    
    /* Remove the jumbotron's default bottom margin */ 
     .jumbotron {
      margin-bottom: 0;
    }
   
    /* Add a gray background color and some padding to the footer */
    footer {
    background-color: #37454D;
    color:#fff;
      padding: 10px;
    }
  </style>

  <div style="background-color:lightgrey" class="text-center">
  <!-- Give full URL -->
  <img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx53RKF84Qif07L__NTVulVu26pHAP9ZSK4wrLupufXv_1rhtzzfjJOFA79ZiM-dLoe6HRtY2gFl9v5UkKJ9UlynyLJTwmRlGBG6PfyJH-O4qoYc2xlp5vCTFeUQoTrv2kYDuv6LXovUNZ/s1600/SB100+copy.png" class="img-responsive" alt="StudentsBlog100" title="Studentsblog100"/>
  </div>

<div class="container">    
  <div class="row">
    <div class="col-sm-12">
     <h3 style="font-weight:bold"><?php if(isset($subject)) { echo $subject; }?></h3>
     <p><?php if(isset($description)) { echo $description; }?></p>
    </div>
  </div>
</div>

<footer class="container-fluid text-center">
  © W3schools100
</footer>
codeigniter send email using html template

  • codeigniter send email html format
  • mail codeigniter 

No comments:

Post a Comment