Cron would work (or scheduled tasks in a Windows environment), although it is not recommended (due to it being a resource hog). However, if you would like something like this, the script could be something similar to this:
bday.php
PHP Code:
<?php
$to = "me@mydomain.com"; //your email address
$subject = "Member's birthdays"; //subject of email
include('dbconnect.php');
$year = date('Y');
$month = date('m');
$results = mysql_query("SELECT * FROM `table` WHERE `birthday` LIKE '$year-$month%'");
if (mysql_num_rows($results) < 1) {
die('There are no members with birthdays this month');
}
else {
while ($qry = mysql_fetch_array($results)) {
if (strtotime($qry['birthday']) <= (time() + 86400*14)) {
$bdays[] = Array($qry['Name'] => $qry['birthday']);
}
}
$message = 'Below is a list of the members and their birthdays that are coming up in the next couple of weeks. \r\n';
$message .= 'The birthdays are as follows: \r\n';
$message .= '-----------------------------------------\r\n\r\n';
foreach ($bdays as $name => $bdate) {
$message .= 'Name (Birthday): '.$name.' ('.$bdate.') \r\n';
}
$from = "From: PHP Script <noreply@mydomain.com";
mail($to, $subject, $message, $from);
}
?>
Note: not tested, but should work with little modification.
Hope this helps.
Bookmarks