I have the following function which is supposed to get a bunch of adverts from the db and email all the people whose adverts have expired. It's almost working but not quite.
public function rerunExpiredMail()
{
// set base url
$base_url = BASE_URL;
// message variable starts off empty
$message = '';
// get ad information
$j = new Ads();
$ad = $j->showAdDetails();
// find ads that were created 61 days ago
$ads = R::findAll('ads',
" DATE_FORMAT(created, '%Y%m%d') = (CURDATE() - INTERVAL ". EXPIRE_JOBS ." +1 DAY)",
array(':email'=>$ad->email, ':id'=>$ad->id));
// loop found ads and send out email
foreach ($ads as $ad) {
$token = accessToken($ad->id);
$link = BASE_URL . "ads/{$ad->id}/rerun/{$token}";
$subject = "Your advert has expired. Rerun it now!";
$message .= "<p>Hi there! Your advert, <strong>{$ad->title}</strong>, has just expired on {$this->app_name}!</p>";
$message .= "<p>You can rerun your advert for another 60 days (free) by simply clicking the link below:</p>";
$message .= "<p><a href={$link}>Click to rerun your advert now</a></p>";
if ($this->sendNotification($subject, $message, $ad->email)) {
//return true;
}
//return false;
}
}
The above code has this effect: emails are sent out to all parties but the first email will be correct, the second email will contain the content for the first email and the content for the second email too, the third email will contain the content for the first, second and third email, and like that successively (the content saved in $message is repeated).
If I uncomment return true;
and return false;
then only the first email in the list gets sent out.
Please help!
Remove the dot from the first $message assign:
$message = "<p>Hi there! Your advert, <strong>{$ad->title}</strong>, has just `enter code here`expired on {$this->app_name}!</p>";