Ok so a little background. I have a website where Ioffer a certain promotional item when a customer spends $5 or more. Right now around midnight each night, I am using a query to spit out a list of the emails for those customers for that day that had qualifying orders by means of a CVS file. (Export a cvs file of all emails of customers who ordered that day from 12:00am until 11:59pm) I then turn around and take that list and do up an email where i email those customers the special promo item (its a digital file site).
The problem is that if i go out of town or dont pay attention and time slips by me or I am too tired to stay up I miss the list for that day. Its a real hassel to have to stay up til midnight so that I can get my list and make sure all the customers who ordered that day get their freebie download.
I have no clue about cron. I am trying to use phpmail to create an executable file. But im not sure what is required or where to begin.
However here is my query for pulling those customers into a cvs file :
if(isset($_GET['action']) && $_GET['action']=="download"){
$this_year = date('Y');
$this_month = date('m');
$this_day = date('d');
$this_day_start = mktime(0,0,0,$this_month, $this_day, $this_year);
$query = "SELECT email FROM ".$glob['dbprefix']."CubeCart_order_sum WHERE status > 1 AND prod_total > 4.99 AND time > ".$this_day_start.";";
//$query = "SELECT email FROM ".$glob['dbprefix']."CubeCart_order_sum WHERE status > 1 AND prod_total > 4.99 AND time > 1272081234;";
$results = $db->select($query);
if($results==TRUE) {
$emailList = "";
for($i=0; $i<count($results); $i++){
if($_POST['incName']==1 && $results[$i]['type']==1){
$emailList .= $results[$i]['title']." ".$results[$i]['firstName']." ".$results[$i]['lastName']." <".$results[$i]['email'].">";
} else {
$emailList .= $results[$i]['email'];
}
$emailList .= ", ";
}
$filename="CustomerEmails_".date("dMy").".txt";
header('Pragma: private');
header('Cache-control: private, must-revalidate');
header("Content-Disposition: attachment; filename=".$filename);
header("Content-type: text/plain");
header("Content-type: application/octet-stream");
header("Content-length: ".strlen($emailList));
header("Content-Transfer-Encoding: binary");
echo $emailList;
exit;
} else {
$msg = $lang['admin']['customers']['no_download_email'];
}
exit;
}
Of course I would love to have my store just send them the freebie automatically after ordering instead of waiting until midnight...but im not sure how to go about doing this. Any ideas???