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

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

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

$database = new database();

//from today
$date_from = date("m") . "-" . date("d");

//to 
$date_till = date("m") . "-" . date("d", strtotime("+ 4 days"));

//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 = "Birthday overview";

$message = "Hello!" . "<br><br>";
$message .= "The following contacts will have their birthday soon; " . "<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') BETWEEN '$date_from' AND '$date_till' ORDER BY `birthday`");
$message .= "<table>";
$message .= "<tr>";
$message .= "<th width='200' style='text-align:left;'>Voornaam</th>";
$message .= "<th width='200' style='text-align:left;'>Achternaam</th>";
$message .= "<th width='200' style='text-align:left;'>E-mail</th>";
$message .= "<th width='200' style='text-align:left;'>Geboortedatum</th>";
$message .= "<th width='50' style='text-align:left;'>Wordt</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'] . " year(s) old</td></tr>";
    }
}

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: No-reply <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