我开发了以下代码,
$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;
这将提供日志的取消订阅而不是黑名单记录。如何仅获取所有黑名单记录(例如,取消订阅者)。
抑制是退回、取消订阅和投诉。 需要查询所有三个终结点才能获取此信息。
请查看 Mailgun-PHP 如果你不想自己编写这段代码。
看起来你已经在使用Mailgun PHP库了,这很棒。根据杰西的回答,抑制分为退回、退订和投诉。
您的代码示例当前正在获取以下行的取消订阅:
$result = $mgClient->get("$domain/unsubscribes");
。您可以通过以下方式更改为获取退回邮件:
$result = $mgClient->get("$domain/bounces");
。或者像这样的抱怨...
$result = $mgClient->get("$domain/complaints");
Mailgun的API参考对于进一步的帮助非常有帮助。
另请注意,当前版本的 PHP API 似乎默认使用版本 2 的 API,而 Mailgun 实际上建议使用 V3。版本 2 似乎只返回了一小部分退回邮件,这有点令人沮丧,因此值得进行升级。在其他调用之前运行此命令...
$mgClient->setApiVersion('v3');
。这应该允许一次性请求更多的压制(我相信限制为 10,000 而不是 300)。希望这有帮助!