我有每月定期帐单,我想在到期前6天向该人发送电子邮件,如果已经发送,则不重新发送。在PHP中工作。我目前在db中有两列:paidUntil和sentReminder,都是DATETIME,但我可以在必要时进行更改。
所以,在伪代码中:
IF(between 6 days before expiration and expiration date AND reminder NOT sent)
send reminder
set that reminder was already sent
else
if the month has past and time for new reminder, go back to top
下个月,重启整个过程。请注意,人们可以在该月的第1天,第9天或任何给定日期过期。请帮忙!
编辑:我基本上希望每个月在成员资格到期前6或5天向某人发送提醒。就这样。这是我的一些代码,但我一直在思考如何检查我发送最后一个提醒的时间是否已经足够生成一个新代码...对不起这里的所有评论!!
$paidUntil = strtotime($oneUser->paidUntil);
$paidUntilMonthPrior = strtotime('-1 month', $paidUntil);
$reminderSent = strtotime($oneUser->reminderSent);
//$paidDateRemindRange = strtotime('-6 days', $paidUntil); //6 days till u remind somebody
$noNeedToSend = strtotime('+25 days', $reminderSent);
//$paidDateReset = strtotime('+1 day', $paidUntil);
//if($thisMonth==date('F',$paidUntil)) {
// $sameMonth=true;
//}
//if($todayTime>$paidDateReminder && $todayTime<$paidUntil && $todayTime>$reminderSent)
// $expirationRange=true;
if($todayTime < $noNeedToSend) {
// is within 25 days from last sending - do nothing
}
elseif($todayTime>$noNeedToSend && $todayTime<$paidUntil) {
//is between 25 days and still less than the paid until time AND has not been sent this cycle
// send expiration email and mark that its been sent
$expirationRange=true;
}
答案 0 :(得分:0)
我认为所有好的代码都是以一个可靠的计划开始的。你有一个可靠的计划。看起来你不需要任何帮助。而且,一般来说,如果人们已经尝试编码并陷入困境,我们只想回答问题。
但也许你错过了找到两个datetime
之间差异的逻辑?如果是这样,这是一个例子:
<?php
$datetime1 = new DateTime('2012-01-11');
$datetime2 = new DateTime('2012-01-13');
$interval = $datetime1->diff($datetime2);
?>