Date Posted:29-05-2017

In this post we will explain Run a Codeigniter in a cron job using CPanelin Codeigniter

Step 1:
Open Cpanel->cronjob

Step 2: add command text box below code
wget http://domainname.com/Cronjob/sendDailyEmail

Step 3:create a new controller give name as Cropjob.php,Create the new  function give name as  as sendDailyEmail  here  add the email function

<?php

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

class Cronjob extends MY_Controller
{
  public function sendDailyEmail()
  {
      $userEmail='example@domain.com';
          $subject='Test';
          $config = Array(       
               'mailtype' => 'html',
                  'charset'  => 'utf-8',
                  'priority' => '1'
          );
          $this->load->library('email', $config);
          $this->email->set_newline("\r\n");
         
              $this->email->from('your mail id', 'Test');
              $data = array(
                   'userName'=> 'Test'
                       );
          $this->email->from('example@domain.in', 'Test');
          $this->email->to($userEmail);  // replace it with receiver mail id
          $this->email->subject($subject); // replace it with relevant subject
         
          $body = $this->load->view('birthday.php',$data,TRUE);
          $this->email->message($body);  
          $this->email->send();
  }
}

step 4:Create HTML file in view folder name as birthday.php after add following code.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Codeigniter mail templates</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<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>

 

Leave a Reply