如何确认每三天发送电子邮件 [英] How to send an email every three days until booking is confirmed

查看:142
本文介绍了如何确认每三天发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户希望他的申请每三天向他的客户发送一封电子邮件,他们没有同意T& C预订,直到预订之日。这将是一个cron工作,但我遇到的问题是如何不间断地检查每三天一个未知的时间。我可以设置大量的其他检查,但在某个阶段,它可能会/将会因为没有足够的检查而中断。每个检查将执行发送电子邮件的相同任务。

I have a client who wants his application to send an email every three days to his customers that have not agreed to T&C for a booking up until the date of the booking. This will be a cron job but the problem I'm having is how to continuously check every three days for an unknown amount of time. I could just set numerous if else checks but at some stage it could/will break because I haven't put in enough checks. Each check will perform the same task of sending the email.

如何每三天更改if else检查?

How can I improve the if else checks for every three days?

我的脚本位于

$sql = "SELECT * FROM bookings " .
    "WHERE DATE(date) > DATE(NOW()) " .
    "AND dateofquote != '' " .
    "AND email != '' " .
    "AND confirmed = 0";

$result = mysql_query($sql);
$num_rows = mysql_numrows($result);

$today = date('Y-m-d');
$count = 3;

if($num_rows){
while($row = mysql_fetch_assoc($result)){
    $date_of_quote = $row['dateofquote'];

    $datetime1 = new DateTime($today);
    $datetime2 = new DateTime($date_of_quote);
    $interval = $datetime1->diff($datetime2);
    $diff = $interval->format('%a');


 // How do I improve this process from here
    if($diff == '3'){
        // send email
    } elseif($diff == '6'){
        // send email
    } elseif($diff == '9'){
        // send email
    } else {
        echo 'something went wrong';
    }

}


推荐答案

使用模数运算符

6%3

将输出0

9%3

在你的情况下

if($diff % 3 == 0){ 
//send email
...}

这篇关于如何确认每三天发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆