geeth
geeth

Reputation: 714

task scheduling in codeigniter

I need to schedule a task to send mail every morning in codeigniter. I am using windows task scheduling. I created a controller function to send the email and scheduled the task in Task scheduler. But it is not working. The following is my controller

Cron.php

<?php


class Cron extends CI_Controller {

public function index() {
    $users = $this->Home_model->getAllUsers();
    foreach($users as $user) {
        $creditBalance = $this->Home_model->creditBalanceofUser($user['UserID']);
        if($creditBalance < 10){
            $this->balanceInfoMail($user['LoginEmailID'], $user['FullName']);
        }
    }
}

public function balanceInfoMail($email, $username) {
    $message = '<div style="background-color: #f3f3f3; max-width: 650px; margin: 0 auto; box-shadow: 0px 0px 25px rgba(0, 0, 0, 0.25);">
                            <!-- header section -->
                            <div style="/*border-bottom: 5px solid #cc342f;*/ border-bottom: 5px solid #fa233d; background-color: #f4f1f1; padding: 20px;">
                                    <div style="text-align: left;">


                                    </div>  
                            </div>
                            <!-- content section -->
                                <div style="padding: 20px 25px; text-align: justify; overflow: hidden; position: relative;">        
                                        <p style="font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #fa233d;">
                                                Dear '.$username.',
                                        </p>
                                        <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">
                                            Kindly note that your SMS balance is low. Please recharge for uninterupted service from sms.fifthsky.com.
                                        </p>


                                        <p style="font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #fa233d;">
                                            Thanks & Regards,
                                        </p>
                                        <p style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: 100; color: #1b1b1b; line-height: 24px;">                                             
                                            Administrator <br/>

                                        </p> 

                                </div>
                                <!-- footer section -->
                            <div style="border-top: 3px solid #fa233d; background-color: #f4f1f1; padding: 10px 25px; text-align: right">

                                <p style="margin: 0; font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #1d1d1d; text-decoration: none; display: inline-block;">0484 4172233&nbsp;  </p>

                                <a href="" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #1d1d1d; text-decoration: none; display: inline-block;">&nbsp; <span style="color: #fa233d;">|</span> &nbsp;Visit Us</a>

                            </div>
                        </div>';

        $this->email->message($message);
        $this->email->to($email);
        $this->email->from(ADMIN_EMAIL, 'Administrator');  
        $this->email->cc(ADMIN_EMAIL);
        $this->email->subject('SMS Balance Information');
        $this->email->send();
}
}

And the following are the steps I followed to create the task

enter image description here

enter image description here

enter image description here

Upvotes: 1

Views: 2700

Answers (1)

user3106394
user3106394

Reputation: 11

CI has to start from index.php, like:

php.exe {CI_root}/index.php controller/function

In this case, cron command can be

D:\xampp\php\php.exe -f D:\xampp\htdoc\SMS\index.php Cron/index

Specifying the use of the index function is necessary.

Upvotes: 1

Related Questions