Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cronjob in codeigniter using cpanel

My website hosting server is hostmonster.com.

My application uses codeigniter framework.

I have a code which sends emails to my users and I want to make it automatic.

I have used the cpanel of the hosting service and I tried to give the command as

php -q www.mysite.com/admin admin sendDailyEmail

my controller is admin and the method is sendDailyEmail and the controller is present inside the application/controllers/admin folder.

I have also set a reminder email to me whenever the cronjob is run.

The email subject reads

Cron php -q /home1/username/public_html/admin admin sendDailyEmail

and the body says

No input file specified

Where do I go wrong.

I have never run cronjobs and this is my first time. I am no good in giving command line instuctions too.

My admin sendDailyEmail code is as follows

function sendDailyEmail() {
    $data = $this->admin_model->getDailyData();
    foreach ($data as $u) {
    if($u->Daily){
     //if(!$u->Amount){
       if ($u->Email=='[email protected]') {

                $user['user_data']['FirstName'] = $u->FirstName;
                $user['user_data']['LastName'] = $u->LastName;
                $user['user_data']['Id']=$u->Id;

                $this->email->clear();
                $this->email->to($u->Email);
                $this->email->from('[email protected]', 'MySite');
                $this->email->subject("My Subject");
                $msg = $this->load->view('emails/daily_view', $user, true);
                $this->email->message($msg);
                if ($this->email->send())
                    $data['message'] = "Daily Emails has been sent successfully";
                else
                    $data['message'] = "Daily Emails Sending Failed";
            }
        }
    }
    $data['main_content']['next_view'] = 'admin_home_view';
    $this->load->view('includes/admin_template', $data);
}
like image 553
spod Avatar asked Oct 05 '13 15:10

spod


People also ask

What is Cron in cPanel?

Cron allows you to schedule jobs at specific intervals or dates. It automates repetitive tasks for better system maintenance. For example, you can create cron jobs for daily or weekly backups.


2 Answers

You can use wget and set the time for whatever you like:

wget http://www.mysite.com/admin/sendDailyEmail

You can also use curl:

curl --silent http://www.mysite.com/admin/sendDailyEmail
like image 52
doitlikejustin Avatar answered Oct 11 '22 20:10

doitlikejustin


For CodeIgniter 2.2.0

You can try this:

 php-cli /home/username/public_html/index.php controller method

or at your case

 php-cli /home/username/public_html/index.php admin sendDailyEmail 

It works fine with me.. Cheers!

like image 34
JiNexus Avatar answered Oct 11 '22 20:10

JiNexus