Location: PHPKode > scripts > PHP Address book > php-address-book_v_1.01_eng/php-address-book_v_1.01_eng/cron.php
<?php
ob_start();
session_start();

$root = $_SERVER['DOCUMENT_ROOT'] . "/";

include_once $root . 'classes/database.class.php';

$database = new database(); 

//to day
$format = 'm-d'; 
$date_till = date ( $format, strtotime ( '+3 days' . date("m.d.y") ) ); 
        

//select mailto clients
$query = $database->query("SELECT * FROM `cal_users` WHERE `mailinglist` = '1'");
while($row = mysql_fetch_assoc($query)){
    $mails[] = $row['email'];
}


//init the mail
$subject = "Verjaardagen overzicht";

$message = "Hallo!" . "<br><br>";
$message .= "The following birthday(s) are coming " . "<br><br>";

$query = $database->query("SELECT `cal_contacts`.*, DATE_FORMAT(`cal_contacts`.`birthday`, '%d-%m-%Y') AS `birthdaynew`,DATE_FORMAT(`cal_contacts`.`birthday`, '%Y') AS `year`, EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(),`birthday`))))+1 AS `age` FROM `cal_contacts` WHERE DATE_FORMAT(birthday, '%m-%d') LIKE '$date_till' ORDER BY `birthday`");
$message .= "<table>";
$message .= "<tr>";
$message .= "<th width='200' style='text-align:left;'>Firstname</th>";
$message .= "<th width='200' style='text-align:left;'>Lastname</th>";
$message .= "<th width='200' style='text-align:left;'>E-mail</th>";
$message .= "<th width='200' style='text-align:left;'>Date of birth</th>";
$message .= "<th width='50' style='text-align:left;'>Getting</th>";
$message .= "</tr>";
while($row = mysql_fetch_assoc($query)){
    $message .= "<tr><td>" . $row['firstname'] . "</td>";
    $message .= "<td>" . $row['lastname'] . "</td>";
    $message .= "<td>" . $row['email'] . "</td>";
    $message .= "<td>" . $row['birthdaynew'] . "</td>";
    if($row['year'] == "0000"){
        $message .= "<td>Unknown</td></tr>";
    } else {
        $message .= "<td>" . $row['age'] . " years</td></tr>";
    }
}
//echo $message;

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Johan Nijdam <hide@address.com>';

//if anything, then mail
if(mysql_num_rows($query) != 0){
    //loop to what mail addresses
    for($i = 0; $i < count($mails); $i++){
        mail($mails[$i], $subject, $message, $headers);
    }
}
?>
Return current item: PHP Address book