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

//include needed files
include_once 'includes/config.php';

//mysqli instance
$mysqli = new mysqli($location, $username, $password, $database);

//init the mail
$subject = "Birthday overview";

$message = "<html>";
$message .= "<head></head>";
$message .= "<body>";
$message .= "Hello!" . "<br><br>";
$message .= "The following birthday(s) are coming " . "<br><br>";

//do the query
$result = $mysqli->prepare("
                    SELECT 
                        `cal_contacts`.`id`, 
                        `cal_contacts`.`firstname`, 
                        `cal_contacts`.`lastname`, 
                        `cal_contacts`.`email`, 
                        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 
                        ? 
                    ORDER BY 
                        `birthday`
                    ");

//bind select
$result->bind_param(s, $date_till);

//bind resultset
$result->bind_result($id,$firstname,$lastname,$email,$birthdaynew,$year,$age);
$result->store_result();

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

//execute
$result->execute();

$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($result->fetch()){
    $message .= "<tr><td>" . $firstname . "</td>";
    $message .= "<td>" . $lastname . "</td>";
    $message .= "<td>" . $email . "</td>";
    $message .= "<td>" . $birthdaynew . "</td>";
    if($year == "0000"){
        $message .= "<td>Unknown</td></tr>";
    } else {
        $message .= "<td>" . $age . " years</td></tr>";
    }
}
$message .= "</body>";
$message .= "</html>";
echo $message;

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$cron_name.' <'.$cron_mail.'>';

//select mailto clients
$user_result = $mysqli->prepare("SELECT
                                `cal_users`.`id`,
                                `cal_users`.`role`,
                                `cal_users`.`username`,
                                `cal_users`.`email`,
                                `cal_users`.`mailinglist`
                            FROM 
                                `cal_users` 
                            WHERE 
                                `mailinglist` = ?
                           ");
$mailinglist = 1;
$user_result->bind_param(i, $mailinglist);
$user_result->bind_result($user_id,$user_role,$user_username,$user_email,$user_mailinglist);
$user_result->execute();

while($user_result->fetch()){
    $mails[] = $user_email;
}

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