3

I am using PHP and MySQL. I am trying to send a mail but it is not working. I want to check two dates and send a mail on a particular date.

   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';    
                }

            }}  
Chris Spittles
  • 15,023
  • 10
  • 61
  • 85
Ankit Sharma
  • 17
  • 1
  • 8

1 Answers1

1

Ok, Please check the following solution:--

 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)
                {
Dinesh Rawat
  • 970
  • 10
  • 32
  • As per my understanding date('Y-m-d') Will work best. "); echo(date("Y-m-d",$t)); // It's a long precess. ?> – Dinesh Rawat Jul 10 '14 at 13:43
  • `strtotime(date('Y-m-d'));` You are generating a date from the current timestamp, then parsing it with `strtotime()` to get it's timestamp, which would just be the result from `time()`. `strtotime(date('Y-m-d'));` Makes no sense, as you're performing a needless loop. – SubjectCurio Jul 10 '14 at 13:48
  • if ($date=time()); He will not be able to compare the two values. Bcoz it will always return false. – Dinesh Rawat Jul 10 '14 at 13:54
  • `echo $today = strtotime(date('Y-m-d')); // User strtotime` This line here. – SubjectCurio Jul 10 '14 at 14:00