erwane/whep-client
Composer 安装命令:
composer require erwane/whep-client
包简介
Webhooks handler for emailing providers.
README 文档
README
This is the base project to easily handle webhooks sent by different emailing providers and uniformizing in a comprehensive object.
This project is not made to be used alone, you need to pick your providers handlers corresponding to your project.
Available providers handlers
| Provider | Package |
|---|---|
| Brevo | erwane/whep-brevo |
| Mailgun | erwane/whep-mailgun |
| Mailjet | erwane/whep-mailjet |
| Postal | erwane/whep-postal |
Usage
composer require erwane/whep-<provider>
use WHEP\Factory; use WHEP\Exception\SecurityException; use WHEP\Exception\WHEPException; use WHEP\ProviderInterface; try { $provider = Factory::provider('<provider>', [ 'client_ip' => $_SERVER['REMOTE_ADDR'] ?? null, // Use your framework correct method to get the client ip. 'callbacks' => [ ProviderInterface::EVENT_BLOCKED => [$this, 'callbackInvalidate'], ProviderInterface::EVENT_BOUNCE_HARD => [$this, 'callbackInvalidate'], ProviderInterface::EVENT_BOUNCE_QUOTA => [$this, 'callbackUnsub'], ], ]); // process the data. $provider->process($webhookData); // Data available from provider getters. $recipient = $provider->getRecipient(); // Launch callback $provider->callback(); } catch (SecurityException $e) { // log ? } catch (WHEPException $e) { // log ? }
Options
You can pass options to Factory::provider('<provider>', $options) method.
All available options are:
client_ip: The client IP who request your url. Defaultnullallowed_ip: Array of IPv4/IPv6 network (range) and allowed IP. Default depends on provider.check_ip: Set to false to bypass security IP check. Default isfalse.signing_key: Your provider private key to validate request came from trusted provider. Defaultnullcallbacks: Youcallableyou want to be called, depends on event type.
Security
Except if your webhook url has a security token, you can't ensure the webhook really came from trusted provider.
Some providers use a signing key to validate data or provide an IP addresses list.
IP validation
When provider publish his IP addresses, you should pass the webhook client IP to the provider.
Factory::provider('mailjet', ['client_ip' => $_SERVER['REMOTE_ADDR'] ?? null]);
When provider is self-hosted, like Postal, you can pass your postal server IP.
Factory::provider('postal', [ 'client_ip' => $_SERVER['REMOTE_ADDR'] ?? null, 'allowed_ip' => [ '10.0.0.1', 'fe80::0023:1', '192.168.0.1/24', ], ]);
You can bypass IP check with check_ip sets to false.
Factory::provider('mailjet', ['check_ip' => false]);
Signing key
When provider support signing key, you can pass your private key with signing_key option.
Factory::provider('mailgun', ['signing_key' => 'my-private-signing-key']);
The validation is done during ProviderInterface::process()
Callbacks
Your callback method are cast when $provider->callback() is called (you decide when).
See Event type & Callbacks section for details.
Factory::provider('<provider>', ['callbacks' => [ProviderInterface::EVENT_UNSUB => [$this, 'callbackUnsub']]]);
Event type & Callbacks
You can configure one callback by event type. Available callbacks are:
| Event | Why event was emitted |
|---|---|
ProviderInterface::EVENT_REQUEST |
You send an e-mail to your provider. |
ProviderInterface::EVENT_DEFERRED |
The send was deferred by provider. |
ProviderInterface::EVENT_BLOCKED |
The recipient e-mail is in provider blocklist. |
ProviderInterface::EVENT_SENT |
E-mail was sent. |
ProviderInterface::EVENT_BOUNCE_SOFT |
E-mail receive a soft-bounce (4xx) with reason. |
ProviderInterface::EVENT_BOUNCE_QUOTA |
Like BOUNCE_SOFT but quota problem detected. |
ProviderInterface::EVENT_BOUNCE_HARD |
E-mail receive a hard-bounce (5xx) with reason. |
ProviderInterface::EVENT_OPENED |
E-mail was opened. |
ProviderInterface::EVENT_CLICK |
A link was clicked. |
ProviderInterface::EVENT_ABUSE |
Recipient report your e-mail as abuse. |
ProviderInterface::EVENT_UNSUB |
Recipient want to unsubscribed from you list. |
ProviderInterface::EVENT_BLOCKLIST |
You provider IP is in MX recipient blocklist (spam/dnsbl). |
ProviderInterface::EVENT_ERROR |
Provider error. |
Methods
ProviderInterface has the following methods:
- getName()
- getTime()
- getType()
- getRecipient()
- getDetails()
- getSmtpResponse()
- getUrl()
- getRaw()
- process()
- callback()
- securityChecked()
getName()
Return provider name.
echo $provider->getName();
getTime()
Get event time as \DateTimeInterface. This represents when hook was received, not event time.
$time = $provider->getTime();
getType()
Return event type. See Event type & Callbacks for all types.
if ($provider->getType() === \WHEP\ProviderInterface::EVENT_UNSUB) { // Do something }
getRecipient()
Return event related e-mail recipient.
echo $provider->getRecipient();
getDetails()
Return provider event details (or reason).
echo $provider->getDetails();
getSmtpResponse()
Return recipient MX SMTP response.
echo $provider->getSmtpResponse();
getUrl()
Return url of clicked link. Available for \WHEP\ProviderInterface::EVENT_CLICK only.
Some providers (mailgun) do not return this information.
echo $provider->getUrl();
getRaw()
Return event raw data as array by default. Return as json if $asJson is true.
$raw = $provider->getRaw(); // raw data in json format. echo $provider->getRaw(true);
process()
Process the webhook data. This method is chainable.
$provider = \WHEP\Factory::provider('mailgun') ->process($webhookData);
callback()
Run you related event type callable if configured.
// This will process data and call self::callbackUnsub($provider) if event is unsub. $provider = \WHEP\Factory::provider('mailgun', [ 'callbacks' => [ \WHEP\ProviderInterface::EVENT_UNSUB => [$this, 'callbackUnsub'], ], ]) ->process($webhookData) ->callback();
securityChecked()
Return true if security was checked. Default to false.
if (!$provider->securityChecked()) { // Your webhook url deserve security. }
erwane/whep-client 适用场景与选型建议
erwane/whep-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 220 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「webhook」 「emailing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 erwane/whep-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 erwane/whep-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erwane/whep-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Smart Emailing API v3 client for PHP
Inbox pattern process implementation for your Laravel Applications
GitHub Webhook Listener with plugin-based API for creating your own triggerered actions
Highly configurable multi-process emailing solution (console command) for yii2.0.
QQ群WebHook机器人助手
统计信息
- 总下载量: 220
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-02