1

I am trying to run a weekly email update via a cron job using codeigniter. Everything works fine if I check it in a browser, however when I run it via a command line it goes through the loop once and then dies on setting the $message variable to the view.

The logs don't show anything useful

Log info

DEBUG - 2013-03-27 20:26:35 --> Email Class Initialized
DEBUG - 2013-03-27 20:26:35 --> File loaded: /email_templates/weekly_user_update.php
DEBUG - 2013-03-27 20:26:36 --> Language file loaded: language/english/email_lang.php

Code in question

public function weekly_update(){

      $this->load->model('statistics_model','stats');
      $this->load->library('email');
      $config['mailtype'] = "html";
      $this->email->initialize($config);

      $users = $this->stats->get_product_users();

      echo "Found ".count($users)." user(s).==".PHP_EOL;
      echo "--Beginning User Parse--".PHP_EOL;
      $count= 0;
      foreach($users as $user){
        echo " Parsing User ".$user['first_name']." ".$user['last_name']."[".$user['user_id']."]".PHP_EOL;
        $this->email->to($user['email']);
        $subject = "Weekly Updates for ".date('m/d/Y');
        $this->email->subject($subject);

        $message = $this->load->view('email_templates/weekly_user_update',$data,TRUE);

          $this->email->message($message);
          echo "  Sending Message to ".$user['email']." '".$subject."'".PHP_EOL;
          $this->email->send();

          echo "  Weekly Update Sent to {$to}!".PHP_EOL;

          $this->email->clear();


    }
}

Please help it's driving me insane!

1 Answers1

0

$data doesn't appear to be set anywhere in this function, so I'm guessing it is dependent on a session or something in a MY_Controller to populate it -- which is not available from CLI

Can't tell you precisely without seeing the rest of your code, but you should be able to track it from that

jmadsen
  • 3,635
  • 2
  • 33
  • 49
  • $data actually does get set, I just removed that part of the code from this post as it contained some sensitive information. – user2217323 Mar 28 '13 at 12:12
  • then there is some similar problem in your $users = area. Stop looking at code & think about your program -- what parts of it get information from outside this function that might be reliant on a session or similar. And please post ALL relevant code ;-) – jmadsen Mar 28 '13 at 22:19