Het kan zijn dat u deze e-mail later krijgt dan voorzien. Daardoor kloppen de datums hierboven niet helemaal. U mag in dat geval rekenen vanaf vandaag. We sluiten niet zomaar af. Mocht u toch twijfelen aarzel niet om ons te contacteren";
mysql_connect($host, $dbuser, $dbpaswd);
mysql_select_db($database);
$initq="SET NAMES utf8;";
$result=mysql_query($initq);
function read($host, $user, $pwd, $db, $query)
{
$eindresultaat=array();
$sqlquery=$query;
$result=mysql_query($sqlquery);
if($result)
{
$aantal=mysql_affected_rows();
for ($i=1; $i<=$aantal; $i++)
{
$resultaatarray=mysql_fetch_array($result);
array_push($eindresultaat, $resultaatarray);
}
}
else
{
$eindresultaat=array();
}
return $eindresultaat;
}
require_once('lib/displaydate.php');
require_once('lib/php_mailer/class.phpmailer.php');
$fp = fopen("reminders_log.txt", "a");
$today = date("F j, Y, g:i a");
$log = "\n\n******************************************************\r";
$log.="******* $today *******\r";
$log.="********************************************************\n \n";
fwrite($fp, $log);
fclose($fp);
// $db = new DB();
$sql = "select tbluserdomains.reminder1, tbluserdomains.reminder2, tbluserdomains.id, tbluserdomains.registrationdate, tbluserdomains.promocode, tbluserdomains.userid, tblusers.username, tbluserdomains.fulldomain, tblusers.firstname, tblusers.lastname
from tbluserdomains
left join tblusers on (tbluserdomains.userid = tblusers.id)
where reminder2=0 and payed=0 and tbluserdomains.onhold=0";
$res = read($host, $dbuser, $dbpaswd, $database, $sql);
if(count($res)>0)
{
$today = mktime(12,0,0,date("m"),date("d"),date("Y"));
$myFile = "lib/mails/betaling.html";
$fh = fopen($myFile, "r");
$betaling = fread($fh, filesize($myFile));
fclose($fh);
$myFile = "lib/mails/afsluiting.html";
$fh = fopen($myFile, 'r');
$afsluiting = fread($fh, filesize($myFile));
fclose($fh);
foreach ($res as $r)
{
$price = 0;
$reminder1 = false;
$reminder2 = false;
$registrationdate = getMkTime($r['registrationdate']);
// the first reminder still needs to be send
unset($mail);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = $smtpserver;
$mail->From = "info@baby-website.be";
$mail->FromName = "Baby-website";
$mail->WordWrap = 200;
if($r['reminder1'] == 0)
{
$reminder1 = true;
$tmp = $today - $registrationdate;
if($tmp >= 604800)
{
//echo $betaling."
";
$title = "Herinneringsemail voor de betaling van uw babywebsite: ".$r['fulldomain'];
$thebody = str_replace("##001##", displaydate($r['registrationdate']), $betaling);
$finish = mktime(12,0,0,splitDate($r['registrationdate'],"m"),splitDate($r['registrationdate'],"d")+14,splitDate($r['registrationdate'],"y"));
$thebody = str_replace("##002##", date("d-m-Y",$finish), $thebody);
$price = 69;
if($r['promocode'] !="")
{
$sql ="select type,amount from tblpromocodes where promocode='".$r['promocode']."'";
// $promo = $db->get_single_row($sql);
$result = read($host, $dbuser, $dbpaswd, $database, $sql);
$promo = $result[0];
if($promo["type"] == "absolute") $price = 69 - $promo["amount"];
if($promo["type"] == "relative") $price = 69 - (69/100*$promo["amount"]);
}
// print $r['username']." | R1-> ".$price."\n";
$thebody = str_replace("##003##", $price, $thebody);
$thebody = str_replace("##004##", $r['username'],$thebody);
$thebody = str_replace("##005##", $r['fulldomain'],$thebody);
}
}
// the second reminder is not send.
else
{
$reminder2 = true;
$tmp = $today - $registrationdate;
if($tmp >= 1209600){
//echo $afsluiting."
";
$title = "Laatse kans om uw babywebsite: ".$r['fulldomain']." verder te blijven gebruiken";
$thebody = str_replace("##001##", displaydate($r['registrationdate']), $afsluiting);
$price = 69;
if($r['promocode'] !="")
{
$sql ="select type,amount from tblpromocodes where promocode='".$r['promocode']."'";
// $promo = $db->get_single_row($sql);
$result = read($host, $dbuser, $dbpaswd, $database, $sql);
$promo = $result[0];
if($promo["type"] == "absolute") $price = 69 - $promo["amount"];
if($promo["type"] == "relative") $price = 69 - (69/100*$promo["amount"]);
}
// print $r['username']." | R2 -> ".$price."\n";
$thebody = str_replace("##003##", $price, $thebody);
$thebody = str_replace("##004##", $r['username'],$thebody);
$thebody = str_replace("##005##", $r['fulldomain'],$thebody);
}
}
if($r['registrationdate']<=$todaymin14)
{
$thebody = str_replace("##006##", $afterdatetext, $thebody);
}
else
{
$thebody = str_replace("##006##", "", $thebody);
}
$mail->Subject = $title;
$mail->Body = $thebody;
$mail->IsHTML(true);
$fp = fopen("reminders_log.txt", "a");
$todaylog = date("F j, Y, g:i a");
if($price > 0) // check when nothing has to be payed
{
if($debug)
{
$mail->AddAddress("kevin@thisconnect.be", $r['firstname']." ".$r['lastname']);
}
else
{
$mail->AddAddress($r['username'],$r['firstname']." ".$r['lastname']);
//echo $r['username'],$r['firstname']." ".$r['lastname'];
}
$mail->AddBCC("bram@thisconnect.be", "Bram verniest");
$mail->AddBCC("kevin@thisconnect.be", "Kevin Goeminne");
if($mail->Send())
{
if($reminder1)
{
$update = "update tbluserdomains set reminder1='".date("Ymd")."' where id=".$r['id'];
$log = "Reminder 1 has been succesfull send at $todaylog to ".$r['username']."\n";
}
if($reminder2)
{
$update = "update tbluserdomains set reminder2='".date("Ymd")."', locked=1 where id=".$r['id'];
$log = "Reminder 2 has been succesfull send at $todaylog to ".$r['username']."\n";
}
// $db->executesql($update);
$result = read($host, $dbuser, $dbpaswd, $database, $update);
}
else
{
if($reminder1)
{
$log = "Reminder 1 has been failed sending at $todaylog to ".$r['username']."\n";
}
if($reminder2)
{
$log = "Reminder 2 has been failed sending at $todaylog to ".$r['username']."\n";
}
}
fwrite($fp, $log);
fclose($fp);
}
}
}
// ############## database ################
mysql_close();
?>