简体   繁体   English

产品过期时发送PHP邮件

[英]PHP mail sending when product got expire

i want to send the mail , when product got expire from before and ondate and after day, in php i was used datediff mysql function with php, but if product expire date comes like 31-1-2012 , the differ value is not suit for my coding , plz help how to solve it , This is my coding 我想发送邮件,当产品从之前,之后和一天之后过期时,在php中我将php与datediff一起使用mysql函数,但是如果产品过期日期如31-1-2012,则不同的值不适合我的编码,请帮助如何解决,这是我的编码

<?php

$sql = mysql_query("SELECT * FROM supplier_product_det");
$results = mysql_num_rows($sql);
//echo '<script>alert("'.$results.'")</script>';
if ($results > 0)
{   

        for($i=0;$i<$results;$i++)
        {
            while($rows = mysql_fetch_array($sql))
            {
             /* print_r($rows['expired_on']);?><br /> <?*/
             $exdate = $rows['expired_on'];
             $curdate = date('Y-m-d'); 
             $datedif = mysql_query("select datediff('".$curdate."','".$exdate."')");
             while( $date = mysql_fetch_array($datedif) )
             {
                //echo $date['0'];
                //echo $rows['pro_code'];
                if (($date['0'])== 1)
                {

                    if(($rows['mailcount'])!== $curdate)
                    {
                        $to = $rows['supplier'];
                        $subject = "Product Expire Intimation";
                        $message = "Dear Mr/Miss/Mrs
                        The Following Your Product Expired 
                        Product Code:".$rows['pro_code']."
                        Product Name:".$rows['product_name']."
                        Product Expire Date:".$rows['expired_on']."";               
                        $from = "tone@bgrow.com";
                        $headers = "From:" . $from;
                        mail($to,$subject,$message,$headers);
                        $checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
                    }


                    //echo $rows['supplier'];

                }
                    if (($date['0'])== 0)
                {
                    if(($rows['mailcount'])!== $curdate)
                    {
                        $to = $rows['supplier'];
                        $subject = "Product Expire Intimation";
                        $message = "Dear Mr/Miss/Mrs
                        The Following Your Product Expired
                        Product Code:".$rows['pro_code']."
                        Product Name:".$rows['product_name']."
                        Product Expire Date:".$rows['expired_on']."";
                        $from = "tone@bgrow.com";
                        $headers = "From:" . $from;
                        mail($to,$subject,$message,$headers);
                        $checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
                    }


                    //echo $rows['supplier'];

                }
                    if (($date['0'])== -1)
                {
                    if(($rows['mailcount'])!== $curdate)
                    {
                        $to = $rows['supplier'];
                        $subject = "Product Expire Intimation";
                        $message = "Dear Mr/Miss/Mrs
                        The Following Your Product will Expire Today 
                        Product Code:".$rows['pro_code']."
                        Product Name:".$rows['product_name']."
                        Product Expire Date:".$rows['expired_on']."";
                        $from = "tone@bgrow.com";
                        $headers = "From:" . $from;
                        mail($to,$subject,$message,$headers);
                        $checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
                    }


                    //echo $rows['supplier'];

                }
             }

            }

        }

}
?>

Write your second select query as follows 编写第二个选择查询,如下所示

SELECT DATEDIFF($exdate, CURRENT_DATE) as diff;

Also, no need to write separate select query you can get same column in first query itself as 另外,无需编写单独的选择查询,您可以在第一个查询本身中获得与

SELECT column1, column2, column3, DATEDIFF(expired_on, CURRENT_DATE) as diff
FROM supplier_product_det

You may need to change position of expired_on and CURRENT_DATE to get correct diff value 您可能需要更改expired_on和CURRENT_DATE的位置以获得正确的差异值

Try something like this... 试试这样的东西...

PHP: $now = date('Y-m-d', strtotime('now'));

- --

SQL: WHERE $now >= DATE_FORMAT(expires, "%Y-%m-%d")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM