结果php只发送一次邮件

问题描述 投票:0回答:1

我有这个代码

while($row = $rs->fetch_object()){
    echo $curl->get($row->site_url, 'sitekontrol', $row->id ).""; 
    if($row->site_url == "changed") {
        sendmail($mailadress);
    }
}

这发送了很多次。我想在完整的结果上发送一次。

这是sitecontrol系统enter image description here

这是enter image description here

php email while-loop
1个回答
1
投票

如果您想在10个站点更改后发送结果,则必须跟踪此变量。

你可能想做这样的事情:

$changes = 0;

while($row = $rs->fetch_object() && $changes < 10){
    echo $curl->get($row->site_url, 'sitekontrol', $row->id ).""; 
    if($row->site_url == "changed") {
        $changes++;
    }
}

if($changes >= 10) {
    sendmail($mailadress);
}

编辑:改为Federico klez Culloca的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.