while 循环、postmarkapp、while 循环发送很奇怪吗?

发布于 2024-10-06 12:34:22 字数 2257 浏览 2 评论 0原文

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

Bob、Susan、Joe,他们都有不活动的站点。

当事情循环时,它给鲍勃发送了一封电子邮件,但电子邮件的正文都是 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();
}

}

When the e-mail sent, it sent the e-mail X amount of times to each person, for example:

Bob, Susan, Joe, all had inactive sites.

When the thing looped, it sent bob an e-mail, but in the e-mail the body was all 3 peoples e-mails.

What have I done wrong?

Is it because I have used $body .= and then not unset it after the e-mail was sent?

Here is my code:

$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();
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的位置 2024-10-13 12:34:22

是的,将此 $body .= "Hi There,\n\n"; 更改

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

Yes, change this $body .= "Hi there,\n\n";

to

$body = "Hi there,\n\n";
神也荒唐 2024-10-13 12:34:22

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

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

当 $body 第一次附加到第一次时,这也将使您避免 E_NOTICE 错误。

Yes, you are correct. Just reset the $body in the beginning of the loop, like this:

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

This will also save you from a E_NOTICE error when $body is appended to the first time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文