Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a mail in PHP and MySQL on a particular date?

Tags:

html

php

mysql

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           =   "[email protected]";  //put email address on which mail send
                        $subject        =   "Query Mail";                   //Put subject of mail here
                       $from        =   "[email protected]";      //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: [email protected]' . "\r\n";

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

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

            }}  
like image 891
Ankit Sharma Avatar asked Feb 03 '26 13:02

Ankit Sharma


1 Answers

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)
                {
like image 195
Dinesh Rawat Avatar answered Feb 05 '26 04:02

Dinesh Rawat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!