我有以下功能,应该从数据库中获取大量广告,并通过电子邮件发送所有广告已过期的人。它几乎可以工作但不完全。
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;
}
}
以上代码有此效果:电子邮件发送给所有各方,但第一封电子邮件将是正确的,第二封电子邮件将包含第一封电子邮件的内容和第二封电子邮件的内容,第三封电子邮件将包含第一,第二和第三封电子邮件的内容,以及相继的内容(重复保存在$ message中的内容)。
如果我取消注释return true;
和return false;
,则只会发送列表中的第一封电子邮件。
请帮忙!
答案 0 :(得分:-1)
从第一个$ message中删除点:
$message = "<p>Hi there! Your advert, <strong>{$ad->title}</strong>, has just `enter code here`expired on {$this->app_name}!</p>";