while循环,postmarkapp,while循环发送它很奇怪?

时间:2010-12-03 15:18:30

标签: php unset

当发送电子邮件时,它会向每个人发送X次电子邮件,例如:

鲍勃,苏珊,乔,都有不活跃的网站。

当事情发生时,它发送了一封电子邮件,但在电子邮件中,身体是所有3个人的电子邮件。

我做错了什么?

是因为我使用了$body .=,然后在发送电子邮件后没有取消它吗?

这是我的代码:

$query = mysql_query("SELECT * FROM `sites` WHERE `active` = '1' AND `banned` = '0'", $link);
while ($result = mysql_fetch_array($query)){


$time = time();
$adayago = $time - 86400;
$logQ = mysql_query("SELECT * FROM `logs` WHERE `site` = '" . $result['id'] . "' AND `type` = 'in' AND `time` > '" . $adayago . "'", $link);
$logR = mysql_fetch_array($logQ);
$logNR = mysql_num_rows($logQ);


if ($logNR > 1){
    // has sent a visit in the last 24 hours
    // do nothing
}else{
    // has not send a visit in the last 24 hours
    $userQ = mysql_query("SELECT * FROM `users` WHERE `id` = '" . $result['owner'] . "'", $link);
    $userR = mysql_fetch_array($userQ);
    mysql_query("UPDATE `sites` SET `active` = '0' WHERE `id` = '" . $result['id'] . "' LIMIT 1", $link);

    $subject = "[ALERT] Your MySite.com listing has been deactivated!";
    $body .= "Hi there,\n\n";
    $body .= "Your listing for " . $result['url'] . " has been deactivated.\n\n";
    $body .= "Your listing has been deactivated because you have not received any votes within the last 24 hours.\n\n";
    $body .= "You must add our button, our link or integrate our vote link into your site and get your members to vote on your topsite listing. Doing this will allow you to stay as an active listing and receive traffic from us.\n\n";
    $body .= "If you have forgotten how to send your members to your vote link, you can visit this page: http://www.mysite.com/vote-details/" . $result['id'] . ".html to learn how to do it.\n\n";
    $body .= "If at any time you need help, please just reply to this e-mail, we are available 12 hours a day, 7 days a week. We would be happy to assist you with setting your vote link up on your website.\n\n";
    $body .= "Kind regards,\nKyle R - MySite CEO\nhttp://www.mysite.com";

    $newPostmark = new Mail_Postmark();
    $newPostmark->addTo($userR['email'], "TGDb Member")
                ->subject($subject)
                ->messagePlain($body)
                ->send();
}

}

2 个答案:

答案 0 :(得分:1)

是的,你是对的。只需在循环开始时重置$ body,如下所示:

...
while ($result = mysql_fetch_array($query)){
  $body = '';
  ...

当第一次追加$ body时,这也可以避免E_NOTICE错误。

答案 1 :(得分:1)

是的,请更改此$body .= "Hi there,\n\n";

$body = "Hi there,\n\n";