【发布时间】:2017-01-06 03:40:20
【问题描述】:
我需要一些帮助,因为我在做 CRON 流程方面还是新手。 我有很多电子邮件,我认为是 1052 封电子邮件。我的计划我想每周发送两次,我将在星期二和星期四进行设置。这样我就可以做一个间隔,因为我认为它会给服务器进程带来压力。如果我错了,请纠正我。所以每天 70 封电子邮件,所以每小时 10 封电子邮件。这是我的表结构。
+-----------+--------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------------------+------+-----+---------+----------------+
| id | int(4) unsigned zerofill | NO | PRI | NULL | auto_increment |
| client_id | int(10) unsigned | NO | | NULL | |
| email | varchar(100) | NO | | NULL | |
| sent | tinyint(1) unsigned | YES | | 0 | |
| sent_date | date | YES | | NULL | |
| excluded | tinyint(1) unsigned | YES | | 0 | |
+-----------+--------------------------+------+-----+---------+----------------+
默认情况下,如果发送了某个电子邮件,sent 列将更改为1(默认为 0)。完成发送电子邮件后,所有电子邮件sent column 将再次返回0。在那个过程中,我没有问题。
我的问题是如何制作一个每小时循环的 PHP 脚本,并且它将在接下来的几天(周二和周四)运行。 在我的 Plesk 面板中,我设置了一个每天都会运行的简单 cron。
我为此使用 CodeIgniter。在发送电子邮件时,我有一个代码,但它会发送所有客户。我只想每小时发送 10 封电子邮件。
public function sendEmail() {
$subj = $this->input->post('email_subject');
$from = 'info@sample.ph';
$cc = $this->input->post('email_cc');
$data['subject'] = $subj;
$content = $this->input->post('email_body');
$this->load->library('email');
$config = array(
'protocol' => 'sendmail',
'smtp_host' => 'mail.sample.ph',
'smtp_port' => 587,
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$email_list = $this->getClientEmails(); //all email for now
$valid_email = array();
$invalid_email = array();
if(count($email_list) > 0) {
for($x = 0; $x < count($email_list); $x++) {
if(valid_email($email_list[$x]['email'])) {
$valid_email[] = $email_list[$x]['email'];
}
//get all invalid emails
/*else {
$invalid_email[] = array(
'id' => $email_list[$x]['id'],
'email' => $email_list[$x]['email']
);
}*/
}
}
$email_string = implode(',', $valid_email);
fd($email_list);
$this->email->set_mailtype("html");
$this->email->from($from, 'SAMPLEAdmin');
$this->email->to($email_string); //get all emails from client
$this->email->cc('jolo@sample.ph');
$this->email->subject($subj);
$this->email->message($content);
$send_mail = $this->email->send();
if($send_mail) {
fp('success');
} else {
fp('failed');
}
echo $this->email->print_debugger();
}
这就是我希望你们明白我真正想要的一切。如果有什么误解,请告诉我。
谢谢。
【问题讨论】:
标签: php codeigniter email cron