Php 如何下载所有抑制列表';使用Mailgun API删除记录

Php 如何下载所有抑制列表';使用Mailgun API删除记录,php,mailgun,Php,Mailgun,我开发了以下代码 $domain = "domain"; $event = "unsubscribes"; //$nextPage = ''; // [bounces, unsubscribes, complaints] // Initiate download on client browser $filename = $domain."_".$event."_".date("c").".csv"; header('Content-Type: text/csv'); header("Cont

我开发了以下代码

$domain = "domain";
$event = "unsubscribes";
//$nextPage = ''; // [bounces, unsubscribes, complaints]

// Initiate download on client browser
$filename = $domain."_".$event."_".date("c").".csv";
header('Content-Type: text/csv');
header("Content-disposition: attachment; filename=".$filename);

// Make the call to the client.
$result = $mgClient->get("$domain/unsubscribes");
//$result = $mgClient->get("$domain/events/" . explode("$domain/events/", $result->http_response_body->paging->next));

$html = "<table><tr><th>Email Address</th><th>Status</th></tr>";

if(count($result->http_response_body->items) > 0) {
    foreach ($result->http_response_body->items as $key) {
         $html .= "<tr>
             <td>" .$key->address."</td></tr>";
    }

} 

$html .= "</table>";  

echo $html;  
$domain=“domain”;
$event=“取消订阅”;
//$nextPage='';//[退票、退订、投诉]
//在客户端浏览器上启动下载
$filename=$domain.“\$event.“\$date”(“c”)。.csv”;
标题(“内容类型:文本/csv”);
标题(“内容处置:附件;文件名=”.$filename);
//给客户打电话。
$result=$mgClient->get($domain/unsubscribes);
//$result=$mgClient->get($domain/events/”。explode($domain/events/”,$result->http\u response\u body->paging->next));
$html=“电子邮件地址状态”;
如果(计数($result->http\u response\u body->items)>0){
foreach($result->http\u response\u body->items as$key){
$html.=”
“$key->address.”;
}
} 
$html.=”;
echo$html;

这将提供日志的取消订阅而不是抑制列表记录。如何仅获取所有抑制列表记录(例如,取消订阅)

抑制是反弹、退订和投诉。您需要查询所有三个端点以获取此信息


如果您不想自己编写此代码,请查看。

看起来您已经在使用Mailgun PHP库了,这很好。根据杰西的回答,压制分为反弹、退订和投诉

您的代码示例当前正在获取此行的取消订阅:

$result = $mgClient->get("$domain/unsubscribes");
…您可以通过以下更改来获取反弹:

$result = $mgClient->get("$domain/bounces");
…或者像这样的抱怨

$result = $mgClient->get("$domain/complaints");
Mailgun's对这里的进一步帮助很有帮助

还要注意,当Mailgun实际建议使用V3时,PHP API的当前版本似乎默认使用API的版本2。版本2似乎只返回一小部分反弹,这有点令人沮丧,因此值得进行升级。在其他呼叫之前运行此命令

$mgClient->setApiVersion('v3');
…这将允许一次请求更多的压制(我认为限制为10000而不是300)。希望这有帮助