<?
session_start();
require("auth.php");

//check date
$today = getdate();
$month = $today['mon']; 
$mday = $today['mday']; 
$year = $today['year'];

$from_date = mktime(0, 0, 0, $month, $mday, $year);

//get details from registration table
$sql = "select * from REGISTERNEW";
$result = db_query($sql);

for ($x = 0; $x < db_numrows($result); $x++) {	
	$row = db_fetch_array($result,1);
	$id = $row["id"];
	$surname = $row["surname"]; 
	$first = $row["first"]; 
	$theday = $row["day_list"]; 
	$themonth = $row["month_list"]; 
	$theyear = $row["year"];
	$receipent = $row["email"];

	$till_date = mktime(0, 0, 0, $themonth, $theday, $year);

	for($ts = $from_date; $ts <= $till_date; $ts += 86400) {
		if ($begtimestamp=="") {
			$begtimestamp=$ts; //this line freezes first timestamp
        }
	}
	$endtimestamp=$ts; //this line freezes the last timestamp
	$totaldays = ($endtimestamp - $begtimestamp) / 86400 - 1;

	if ($totaldays == 7) {
		$subject="An invitation from the *chill*";
		$header="From: TheChillClub";
		$footer="\n\n*chill*,".
		"\nUnit 111, Block B,".
		"\nPhileo Damansara 2,".
		"\nOff Jalan Damansara,".
		"\n46350 Petaling Jaya".
		"\nTel. + 60.03.74919438 / 28".
		"\ninfo@thechillclub.com";
		$message="\n\nHi ". $first . ",\nSince your birthday is coming up soon, we at *chill* were wondering whether we would have the privilege of you celebrating your birthday with us.".
		"\n\nIf that’s a big, resounding ‘YES’ on your part, give us a call at 03-7491 9438 / 28 or send an email to info@thechillclub.com.".
		"\n\nOkay. This may sound a bit odd but don’t get li’l innocent us wrong. Should you require personal attention for your jubilee, give Sam a call at 016-2926038.".
		"\n\nTa for now. Hope to be partying with you soon.". $footer;
		
		mail($receipent,$subject,$message,$header);
	}
}
?>