You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何按时间筛选Mailgun退信?Laravel获取近1小时退信求助

How to Fetch Only Last Hour's Bounces with Mailgun API

Hey there! I’ve tinkered with Mailgun’s APIs a fair bit, so let me walk you through how to filter bounces to only the last hour—you’re closer than you think!

Mailgun’s /bounces endpoint does support time-based filtering, even if it’s easy to miss机器人ata events 良**Sched,外ao events供电, Gsl收到. The key parameter you need is created_after, which lets you specify a cutoff time; only bounces created after that time will be returned.

Here’s how to adjust your Laravel code to make this work:

First, we’ll calculate the timestamp for one hour ago using Laravel’s built-in Carbon library (super handy for date handling):

use Carbon\Carbon;

// Generate an ISO 8601 formatted timestamp for 1 hour prior to now
$oneHourAgo = Carbon::now()->subHour()->toIso8601String();

// Update your GET request to include the filter parameter
$response = Http::get(
    'https://api:' . env('MAILGUN_SECRET') . '@api.mailgun.net/v3/' . env('MAILGUN_DOMAIN') . '/bounces',
    [
        'created_after' => $oneHourAgo
    ]
);

A quick note on the parameter:

  • Mailgun accepts both ISO 8601 strings (like 2024-05-20T14:30:00Z) and Unix timestamps (like 1716234600) for created_after—either will work, but ISO 8601 is more readable for debugging.
  • If you ever need to filter older ranges later, there’s also a created_before parameter you can use alongside this one.

If you end up with a lot of bounces in an hour, you can add limit and skip parameters to handle pagination, but for most use cases, the above should get you exactly the last hour’s bounces you need.

内容的提问来源于stack exchange,提问作者Senthurkumaran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 15:07:52