Hello Guys,

My problem here is I want to check every row of the data if it's in the range of 2 days before today. and will send the email of it's name who fit the condition of 2days before.

<?php
//********************************************************
//2008/07/16    Yoshifumi Tagawa
//********************************************************
    $date_today = date("Y/m/d H:i:s");


//********************************************************
//No Cache
//********************************************************
    header("Content-Type: text/html; charset=文字コード");
    header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
    header("Last-Modified: ". gmdate("D, d M Y H:i:s"). " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");


//********************************************************
//Include File
//********************************************************
    include ("../../include.php");


//********************************************************
//Get DB Visitor List Data
//********************************************************
    $dsn = "VISITOR_LIST";
    $usr = "";
    $pwd = "";

    $selyear=$_REQUEST["selyear"];

    $sql = "SELECT * ";
    $sql .="FROM LIST ";
    $sql .="WHERE RELEASE = 1 ";
    $sql .="AND (TEMP_FLG IS NULL or TEMP_FLG ='') ";
    $list = GetDb_Odbc($dsn,$usr,$pwd,$sql);

if (!$list)
{
    exit("Error in SQL");

}

echo "<table><tr>";
echo "<th>DEPARTURE_DATE</th>";

for($i_row=0; $i_row<count($list); $i_row++){

        $DEPARTURE_DATE = $list[$i_row]["DEPARTURE_DATE"];


}
$ddate = strtotime($DEPARTURE_DATE); //--> which results to 1332866820





$tdate = strtotime("now");
echo ($tdate),"<br> ";
echo ($ddate),"<br> "; 

$total = $tdate - $ddate;


if ($total >=86300 && $total <=259199)
{
    //define the receiver of the email
$to = 'aab_system-development@mhps.com';
//define the subject of the email
$subject = 'Test email'; 
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail."; 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";

}

echo ($total);
//if ($ddate - $tdate >=86300 && $ddate - $tdate  <=259199)
//{
    //echo"Great";

//}

$yourdatetime = '2009-08-21 1.45 PM';
$timestamp = strtotime($yourdatetime);

//while (odbc_fetch_row($list))
//{
    //$depdate=odbc_result($list,"DEPARTURE_DATE");
    //echo "<tr> <td>$depdate</td>";
//}

//odbc_close($conn);
//echo"</table>";
//echo date("m/d/Y");
//if(date("m/d/Y") == $dend)
//{
//  echo"String";
//}




?>

Recommended Answers

All 3 Replies

As I understood you save dates in your db as timestamps int(10) so the first thing you have to do is finding the timestamp the day before yesterday. If you just want 48 hours before a current timestamp it is very easy, get the current timestamp with date("U") and then subtract (48 * 60 * 60) seconds. Knowing that timestamp, put it in your WHERE clause.

Your code has also many logical errors that are partially irrelevant, you just have to think once again what you want to do , and understand what you are actually doing.

I already solved my previous problem but now I want my emails not to be sending one by one if the program met the condition. I want to email all the list in one messages.
Thank you and best regards.

<?php
//********************************************************
//2008/07/16    Yoshifumi Tagawa
//********************************************************
    $date_today = date("Y/m/d H:i:s");


//********************************************************
//No Cache
//********************************************************
    header("Content-Type: text/html; charset=文字コード");
    header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
    header("Last-Modified: ". gmdate("D, d M Y H:i:s"). " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");


//********************************************************
//Include File
//********************************************************
    include ("../../include.php");


//********************************************************
//Get DB Visitor List Data
//********************************************************
    $dsn = "VISITOR_LIST";
    $usr = "";
    $pwd = "";

    $selyear=$_REQUEST["selyear"];

    $sql = "SELECT * ";
    $sql .="FROM LIST ";
    $sql .="WHERE RELEASE = 1 ";
    $sql .="AND (TEMP_FLG IS NULL or TEMP_FLG ='') ";
    $list = GetDb_Odbc($dsn,$usr,$pwd,$sql);

if (!$list)
{
    exit("Error in SQL");
}


for($i_row=0; $i_row<count($list); $i_row++){
        $ID = $list[$i_row]["ID"];
        $NO = $i_row + 1;
        $DEPARTURE_DATE = $list[$i_row]["DEPARTURE_DATE"];
        $NAME_FAMILY = $list[$i_row]["NAME_FAMILY_E"];
        $NAME_FIRST = $list[$i_row]["NAME_FIRST_E"];





$ddate = strtotime($DEPARTURE_DATE); //--> which results to 1332866820
$tdate = strtotime("now");



$total = $tdate - $ddate;


if ($total >=172800 && $total <=259199)
{

$to = 'aab_system-development@mhps.com';

$subject = "2 days before Departure Date:" ." $NAME_FAMILY" ." $NAME_FIRST" ; 

$message = "DEPARTURE DATE:" . "$DEPARTURE_DATE";
$message2 = "$NAME_FAMILY" ."$NAME_FIRST"; 

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

$mail_sent = @mail( $to, $subject, $message, $message2, $headers );

echo $mail_sent ? "Mail sent" : "Mail failed"; 
echo ($DEPARTURE_DATE),"<br>";
echo "$NAME_FAMILY" . "  $NAME_FIRST", "<br>";   
echo "Successful", "<br>";
}
}






?>

Just collect emails you want to sent to in an array variable, then after ending the looping, assign your $to in mail() with the value like user@example.com, anotheruser@example.com by simply implode the array.
for detail mail() descriptions, please refer to http://php.net/manual/en/function.mail.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.