Reputation: 31
Actually I want to perform the cron job those particular time of session call automatically send the email also I'm calling the controller particular in CI but it unable to perform the cron job.?
error :
/home/a7ndzp5tm2vd/public_html/projects/PolicyManager/insurancecompany/application/controllers/Sendsms_email.php: line 1: ?php: No such file or directory /home/a7ndzp5tm2vd/public_html/projects/PolicyManager/insurancecompany/application/controllers/Sendsms_email.php: line 3: syntax error near unexpected token
'BASEPATH'
/home/a7ndzp5tm2vd/public_html/projects/PolicyManager/insurancecompany/application/controllers/Sendsms_email.php: line 3:if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sendsms_email extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->model('Product');
$this->load->model('queries');
$this->load->model('User_model');
$this->load->library('input');
}
public function index() {
$this->load->library('email');
if($this->input->is_cli_request())
{
@$r1 = $this->user_model->smsten();
//print_r($r1);
if ($r1 != '') {
foreach ($r1 as $key => $users):
$encryption_key = 1234567812345678;
$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
$cn = $users['contactno'];
$cn1 = $cn . ':' . $iv;
$econtactnol = explode(':', $cn1);
$dcontactnol = openssl_decrypt($econtactnol[0], AES_256_CBC, $encryption_key, 0, $econtactnol[1]);
$cname = $users['name'];
$cname1 = $cname . ':' . $iv;
$ename1 = explode(':', $cname1);
$dname1 = openssl_decrypt($ename1[0], AES_256_CBC, $encryption_key, 0, $ename1[1]);
$emailid = $users['email'];
$emailid1 = $emailid . ':' . $iv;
$eemailid = explode(':', $emailid1);
$demail = openssl_decrypt($eemailid[0], AES_256_CBC, $encryption_key, 0, $eemailid[1]);
$p_vehicle= $users['vechicle_no'];
$p1_vehicle = $p_vehicle . ':' . $iv;
$v_vehicle[] = explode(",", $p_vehicle);
//print_r($v_vehicle);
foreach ($v_vehicle as $k_vehicle => $v1_vehicle) {
foreach ($v1_vehicle as $k1_vehicle => $k2_vehicle) {
$ss_vehicle[] = $k2_vehicle . ":";
}
}
$count_v_vehicle= count($ss_vehicle);
for ($i = 0; $i < $count_v_vehicle; $i++) {
$dvehicleno = openssl_decrypt($ss_vehicle[$i], AES_256_CBC, $encryption_key, 0);
$table_vehicle_value[] = $dvehicleno ;
}
$p = $users['GROUP_CONCAT(p.policyno)'];
$p1 = $p . ':' . $iv;
// $epolicydetail = explode(':', $p1);
//print_r($p);
$v[] = explode(",", $p);
foreach ($v as $k => $v1) {
foreach ($v1 as $k1 => $k2) {
$ss[] = $k2 . ":";
}
}
$count_v = count($ss);
for ($i = 0; $i < $count_v; $i++) {
$dpolicydetail = openssl_decrypt($ss[$i], AES_256_CBC, $encryption_key, 0);
$shw2[] = $dpolicydetail . ",";
$table_poilcy_value[] = $dpolicydetail ;
}
$sa = rtrim(join($shw2), ',');
$count_policy= count($table_poilcy_value);
echo"\n"; // echo $dcontactnol;
$contactno = $dcontactnol; /* Separate mobile no with commas */
$message = "Your policy $sa will be expired in 10 days.";
// print_r($message);
$senderId = "DEMOOS"; /* Sender ID */
$serverUrl = "msg.msgclub.net";
$authKey = "14f5d3ca75bc4de1761d4af9e7d83d38"; /* Authentication key (get from sms service provider) */
$route = "1";
$this->sendsmsGET($contactno, $senderId, $route, $message, $serverUrl, $authKey);
$output='<h3>'.$message.'</h3>';
$output .= '<table style="width:100%; border: 1px solid black;
border-collapse: collapse;">';
$output .= '<tr style="width:100%; border: 1px solid black;
border-collapse: collapse;">
<td style="text-align:center; border: 1px solid black; border-collapse: collapse;" colspan="3">Policy Reminder</td>
</tr>';
$output .= '
<tr>
<tr style="width:100%; border: 1px solid black;
border-collapse: collapse;">
<td style="width:30%; border: 1px solid black;
border-collapse: collapse;">Policy No</td>
<td style="width:50%;border:1px solid black;border-collapse:collapse">Vehicle No.</td>
</tr>';
for ($record=0;$record<$count_policy;$record++)
{
$output .= ' <tr style="width:100%; border: 1px solid black;
border-collapse: collapse;" >
<td style=" border: 1px solid black;
border-collapse: collapse;">' . $table_poilcy_value[$record] . '</td>
<td style=" border: 1px solid black;
border-collapse: collapse;">'.$table_vehicle_value[$record].'</td>
</tr>
';
}
$output .= '</table>'; // print_r($output);
$to_email = "[email protected]";
$from_email = "[email protected]";
$subject = "reminder for policy";
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($output);
//Send mail
if($this->email->send())
{ // echo "succesfully";
}
unset($v_vehicle);
unset($v);
unset($ss_vehicle);
unset($ss);
unset($dcontactnol);
unset($shw2);
unset($table_poilcy_value);
endforeach;
} }
}
}
?>
Upvotes: 0
Views: 134
Reputation: 3237
You're not showing exactly HOW you're trying to run the cron, but this is how you should:
* * * * * php /home/path/to/main/codeigniter/index.php controller_name method_name "parameter"
Parameter is optional.
Replace the * * * * *
with your desired schedule and the path for your actual path. For instance, the site I'm working on today lives on /home/webuser/public/www/
so if I wanted to run something (a method called hourly housekeeping) on my dedicated cron controller (conveniently called "Cron") every hour on the hour I'd do:
00 * * * * php /home/webuser/public/www/index.php cron hourly_housekeeping
As a safeguard, you should run cron tasks on a dedicated controller which cannot be accesed through a browser. You can use Codeigniter's is_cli()
to make sure the execution is being initiated through the CLI and refuse to run otherwise.
For that purpose, you may have something like this in your controller construct:
if (!$this->input->is_cli_request()) show_error('Here be dragons. No browsers served here');
Hope you can get it to work
Upvotes: 0