【问题标题】:How to send a mail in PHP and MySQL on a particular date?如何在特定日期用 PHP 和 MySQL 发送邮件?
【发布时间】:2014-07-09 07:34:02
【问题描述】:

我正在使用PHPMySQL。我正在尝试发送邮件,但它不起作用。我想检查两个日期并在特定日期发送邮件。

   if (isset($_POST['mail_sub']))
          { 
            $selectDate  = "select * from insurance_data";
            $querydate   =  mysql_query($selectDate) or die (mysql_error());
            while ($roedate = mysql_fetch_array($querydate))
            {
                $date1 = $roedate['duedate'];
                $date=date('Y-m-d',strtotime($date1.' -3 days'));
                echo '<br>';
                echo  $date;
                echo $today = date('Y-m-d');

                if ($date==$today)
                {
                          $to           =   "2606ankit@gmail.com";  //put email address on which mail send
                        $subject        =   "Query Mail";                   //Put subject of mail here
                       $from        =   "2606ankit@gmail.com";      //put email address from 
                   //email body start
                       $body        .=  "<label class='font_Style'>Alert</label>";
                   // Always set content-type when sending HTML email

                        $headers  = 'MIME-Version: 1.0' . "\r\n";
                        $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

                    // More headers
                    $headers .= 'From: '.$from. "\r\n";

                    //if you need to send cc mail then uncomment below line and change email address
                    //$headers .= 'Cc: myboss@example.com' . "\r\n";

                     mail($to,$subject,$body,$headers);

                    //echo 'asdfasdf';
                }
                else
                {
                    echo 'nahi';    
                }

            }}  

【问题讨论】:

  • 你可以像这样匹配两个日期 make strtotime 然后比较日期

标签: php html mysql


【解决方案1】:

好的,请检查以下解决方案:--

 if (isset($_POST['mail_sub']))
          { 
            $selectDate  = "select * from insurance_data";
            $querydate   =  mysql_query($selectDate) or die (mysql_error());
            while ($roedate = mysql_fetch_array($querydate))
            {
                $date1 = $roedate['duedate'];
                $date=strtotime($date1.' -3 days'); // Remove the date
                echo '<br>';
                echo  $date;
                echo $today = strtotime(date('Y-m-d')); // User strtotime

                if ($date==$today)
                {

【讨论】:

  • 根据我的理解 date('Y-m-d') 效果最好。 ”);回声(日期(“​​Y-m-d”,$t)); // 这是一个长进动。 ?>
  • strtotime(date('Y-m-d')); 您正在从当前时间戳生成一个日期,然后用strtotime() 解析它以获取它的时间戳,这将是time() 的结果。 strtotime(date('Y-m-d')); 没有意义,因为您正在执行一个不必要的循环。
  • if ($date=time());他将无法比较这两个值。因为它总是会返回 false。
  • echo $today = strtotime(date('Y-m-d')); // User strtotime 这行在这里。
猜你喜欢
  • 2018-04-27
  • 2014-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-13
相关资源
最近更新 更多