我需要安排一项任务,每天早上在codeigniter中发送邮件。我正在使用Windows任务调度。我创建了一个控制器功能来发送电子邮件并在任务调度程序中安排任务。但它没有用。 以下是我的控制器
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 </p>
<a href="" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #1d1d1d; text-decoration: none; display: inline-block;"> <span style="color: #fa233d;">|</span> 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();
}
}
以下是我创建任务所遵循的步骤
答案 0 :(得分:0)
CI必须从index.php开始,例如:
php.exe {CI_root}/index.php controller/function
在这种情况下,cron命令可以是
D:\xampp\php\php.exe -f D:\xampp\htdoc\SMS\index.php Cron/index
必须指定使用索引函数。