在PHP中调度多封电子邮件
我创建了一个系统,它接收查询,在数据库中执行查询,然后用返回的数据创建一个HTML表。然后,这些表格保存在系统中以供进一步访问,用户可以通过电子邮件将其发送给多个接收者 一切都很好,但现在我必须安排电子邮件。需要在一周后发送“表X”,两周后发送“表Y”。我该怎么做?我已经查找了cron/WindowsTasks,但我不知道如何使每个表都自动执行,因为用户可以不断创建不同的表 我使用了CodeIgniter和PHPMailerMaster来实现它 这是TableViewer的屏幕截图,它是葡萄牙语的,但它包含: |标题|配置|发送| XLS生成器|上次发送| 对于创建的每个表。(只是为了让您了解它是如何工作的)在PHP中调度多封电子邮件,php,codeigniter,email,scheduled-tasks,phpmailer,Php,Codeigniter,Email,Scheduled Tasks,Phpmailer,我创建了一个系统,它接收查询,在数据库中执行查询,然后用返回的数据创建一个HTML表。然后,这些表格保存在系统中以供进一步访问,用户可以通过电子邮件将其发送给多个接收者 一切都很好,但现在我必须安排电子邮件。需要在一周后发送“表X”,两周后发送“表Y”。我该怎么做?我已经查找了cron/WindowsTasks,但我不知道如何使每个表都自动执行,因为用户可以不断创建不同的表 我使用了CodeIgniter和PHPMailerMaster来实现它 这是TableViewer的屏幕截图,它是葡萄牙语
如果有人有任何想法。这里有一个函数,它在PHP中模拟crontab。您可以将其用于动态crontab,这样每个表都可以有自己独特的频率
function parse_crontab($time, $crontab) {
// Get current minute, hour, day, month, weekday
$time = explode(' ', date('i G j n w', strtotime($time)));
// Split crontab by space
$crontab = explode(' ', $crontab);
// Foreach part of crontab
foreach ($crontab as $k => &$v) {
// Remove leading zeros to prevent octal comparison, but not if number is already 1 digit
$time[$k] = preg_replace('/^0+(?=\d)/', '', $time[$k]);
// 5,10,15 each treated as seperate parts
$v = explode(',', $v);
// Foreach part we now have
foreach ($v as &$v1) {
// Do preg_replace with regular expression to create evaluations from crontab
$v1 = preg_replace(
// Regex
array(
// *
'/^\*$/',
// 5
'/^\d+$/',
// 5-10
'/^(\d+)\-(\d+)$/',
// */5
'/^\*\/(\d+)$/'
),
// Evaluations
// trim leading 0 to prevent octal comparison
array(
// * is always true
'true',
// Check if it is currently that time,
$time[$k] . '===\0',
// Find if more than or equal lowest and lower or equal than highest
'(\1<=' . $time[$k] . ' and ' . $time[$k] . '<=\2)',
// Use modulus to find if true
$time[$k] . '%\1===0'
),
// Subject we are working with
$v1
);
}
// Join 5,10,15 with `or` conditional
$v = '(' . implode(' or ', $v) . ')';
}
// Require each part is true with `and` conditional
$crontab = implode(' and ', $crontab);
// Evaluate total condition to find if true
return eval('return ' . $crontab . ';');
}
我认为您不需要管理两个表。它可以通过一个表来实现
$time_to_run = parse_crontab(date('Y-m-d H:i:s'), '* * * * *')