Let's say there is an ExpiryDate field in the table with events. 
To send email if event was expired create new php file (dailysendmail.php for example), place this file under generated output directory. 
Here is a sample script (for MySQL database):
<?php
include
("include/dbcommon.php");
global $dal;
$dalTableName
= $dal->Table("TableName");
$rstmp
= $dalTableName->Query("DateDiff(now(),ExpiryDate)>0","");;
while ($datatmp = db_fetch_array($rstmp))
{
       
//send email for each record
        $email
=$datatmp["EmailField"];
       
//EmailField is your actual field name
        $msg
="This event was expired\r\n";
        $msg
.="FieldName1: ".$datatmp["FieldName1"]."\r\n";
        $msg
.="FieldName2: ".$datatmp["FieldName2"]."\r\n";    
        $subject
="Expired";
        runner_mail
(array('to' => $email, 'subject' => $subject, 'body' => $msg));      }
//FieldName1, FieldName2 and ExpiryDate are your actual field names, TableName is your actual table name
?>


To apply this sample for MSSQL database edit SQL query in the following way:
$rstmp = $dalTableName->Query("DATEDIFF(day, GETDATE(), ExpiryDate)>0","");

and for MS Access:
$rstmp = $dalTableName->Query("DateDiff('d', Now(), ExpiryDate)>0","");


Then use cron to run this script on timely fashion i.e. once a day. 
You can use SetCronJob service to run this script if cron is disabled on your web server:
http://www.setcronjob.com/

Here is a step-by-step instruction on how to set up cron job usign SetCronJob:
1. register on the http://www.setcronjob.com/
2. activate your account and login,
3. go to Control Panel and click on the 'Create new cron job' link,
4. fill 'URL to call' with correct URL to your script. For example your generated files are under 'phprunner' directory:
http://yourhosting.com/phprunner
So correct URL will be:
http://yourhosting.c...ilysendmail.php
5. Save. 

1 Comments


  1. I got an error saying:
    Fatal error: Call to a member function Query() on a non-object in .../dailysendmail.php on line 5


    my Code is:
    Table("Container");
    $rstmp = $dalTableName->Query("DateDiff(now(),arivalDate)<7","");;

    while ($datatmp = db_fetch_array($rstmp))
    {

    $email="me@yahoo.com";

    $msg="This container arrive in a week \r\n";
    $msg.="ContainerNo: ".$datatmp["ContainerNo"]."\r\n";
    $msg.="arivalDate: ".$datatmp["arivalDate"]."\r\n";
    $subject="Container arrive next week ";
    runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg));

    }
    ?>

    ReplyDelete

Post a Comment