实际上,我想在会话调用的特定时间执行cron作业,自动发送电子邮件,而且我正在调用CI中特定的控制器,但它无法执行cron作业。
错误:
/home/a7ndzp5tm2vd/public_html/projects/PolicyManager/insurancecompany/application/controllers/Sendsms_email.php:第1行:?php:无此类文件或目录 /home/a7ndzp5tm2vd/public_html/projects/PolicyManager/insurancecompany/application/controllers/Sendsms_email.php:第3行:意外令牌
'BASEPATH'
附近的语法错误 /home/a7ndzp5tm2vd/public_html/projects/PolicyManager/insurancecompany/application/controllers/Sendsms_email.php:第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 = "xyz@gmail.com";
$from_email = "xyz@gmail.com";
$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;
} }
}
}
?>
答案 0 :(得分:0)
您没有完全显示尝试运行cron的方式,但这是应该的方式:
* * * * * php /home/path/to/main/codeigniter/index.php controller_name method_name "parameter"
参数是可选的。
将* * * * *
替换为所需的时间表和实际路径。例如,我今天正在工作的网站位于/home/webuser/public/www/
上,因此,如果我想每小时在我专用的cron控制器(通常称为“ Cron”)上运行某些操作(一种称为“小时内清洁”的方法),会做:
00 * * * * php /home/webuser/public/www/index.php cron hourly_housekeeping
为安全起见,应在无法通过浏览器访问的专用控制器上运行cron任务。您可以使用Codeigniter的is_cli()
确保通过CLI启动执行,否则拒绝运行。
为此,您的控制器构造中可能包含以下内容:
if (!$this->input->is_cli_request()) show_error('Here be dragons. No browsers served here');
希望您可以使用它