-1

我分别存储了日(10)、月(4)和年(1993)。如何将其与当前日期进行比较?如果日期匹配,则使用 cron 向 myemail@gmail.com 发送电子邮件。

这是代码:

<?php
include"connect_mysql.php";
$reminder_dates = mysql_query("SELECT*FROM registration_form");
while($row = mysql_fetch_array($reminder_dates)){
$main_dob_day = $row['main_dob_day'];
$main_dob_month = $row['main_dob_month'];   
$main_dob_year = $row['main_dob_year'];
}
?> 
4

3 回答 3

1
$main_date   = "{$main_dob_year}-{$main_dob_month}-{$main_dob_day}";
$todays_date = date("Y-m-d");
$today       = strtotime($todays_date);
$main_dt     = strtotime($main_date);

if($main_dt == $today)
{
  $valid = "send email";
  echo $valid;
}

它会起作用的

于 2012-07-09T11:57:57.577 回答
0

也许是这样的:

$old_date = "2006-01-16"; // Create this from the 3 strings you have in the db
$old_date = strtotime($old_date); 

$todays_date = date("Y-m-d"); 
$todays_date = strtotime($todays_date); 


if ($old_date == $todays_date)
 print "equal";
else
 ....

编辑:在回复您的评论时,您可以使用日期函数获取当前日期和月份,如下所示:

$m = date("m");
$d = date("d");
于 2012-07-09T09:42:29.850 回答
0

您可以在 SQL 查询中直接进行比较,然后循环将向查询返回的所有行发送电子邮件:

<?php
    include"connect_mysql.php";
    $sql = "
        SELECT *
        FROM registration_form
        WHERE 
            main_dob_month = MONTH(CURDATE()) AND 
            main_dob_day = DAYOFMONTH(CURDATE())";

    $reminder_dates = mysql_query($sql);
    while($row = mysql_fetch_array($reminder_dates))
    {
        // send email(s)
    }
?> 
于 2012-07-09T09:50:17.533 回答