定制 mailbino/laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mailbino/laravel

Composer 安装命令:

composer require mailbino/laravel

包简介

Laravel SDK for Mailbino: mail driver and API client

README 文档

README

Laravel SDK for Mailbino: transactional email that's easy to test.

Provides both a Laravel mail driver (use Mail::send() as usual) and a direct API client for Mailbino-specific features like tags, metadata, scoping, and test mode.

Installation

composer require mailbino/laravel

Configuration

Add your API token to .env:

MAIL_MAILER=mailbino

MAILBINO_API_TOKEN=mbn_live_xxxxxxxxxxxx

Optionally publish the config file:

php artisan vendor:publish --tag=mailbino-config

Mail driver setup

Add the mailbino mailer to config/mail.php:

'mailers' => [
    'mailbino' => [
        'transport' => 'mailbino',
    ],
    // ...
],

That's it. All Mail::send() calls now go through Mailbino.

Usage

Standard Laravel Mail (zero changes needed)

Mail::to($user)->send(new WelcomeMail($user));

With Mailbino-specific features

Use custom headers to pass tags, metadata, and scoping through the standard mail interface:

Mail::to($user)->send(new InvoiceMail($invoice));

// In your Mailable's headers() method:
public function headers(): Headers
{
    return new Headers(
        text: [
            'X-Mailbino-Tags' => 'invoice, billing',
            'X-Mailbino-Scope-Type' => 'invoice',
            'X-Mailbino-Scope-Id' => $this->invoice->id,
            'X-Mailbino-Metadata' => json_encode(['amount' => $this->invoice->total]),
        ],
    );
}

Available headers:

Header Description
X-Mailbino-Tags Comma-separated tags
X-Mailbino-Scope-Type Scope type (e.g. order, user)
X-Mailbino-Scope-Id Scope ID
X-Mailbino-Metadata JSON-encoded metadata object
X-Mailbino-Test-Recipient Override test recipient for this message
X-Mailbino-External-Id Your own message ID (UUID)

Direct API client

For full control, use the Mailbino facade:

use Mailbino\Laravel\Facades\Mailbino;

// Send an email
$result = Mailbino::send([
    'from' => 'noreply@m.yourapp.com',
    'from_name' => 'Your App',
    'to' => ['email' => 'user@example.com', 'name' => 'John'],
    'subject' => 'Your invoice is ready',
    'html' => '<h1>Invoice</h1>',
    'tags' => ['invoice'],
    'metadata' => ['invoice_id' => 'INV-123'],
    'scope_type' => 'invoice',
    'scope_id' => 'INV-123',
]);

// $result = ['message_id' => '...', 'status' => 'queued']

// Query messages
$messages = Mailbino::messages(['status' => 'delivered', 'to_email' => 'user@example.com']);

// Get a specific message
$message = Mailbino::message('a1b2c3d4-...');

// Get message events
$events = Mailbino::events('a1b2c3d4-...');

Test Mode

Mailbino has built-in test mode. Enable it in the Mailbino dashboard and all emails are redirected to your test recipients with a banner showing the original address.

Option 1: Dashboard

Enable test mode on your app in the Mailbino dashboard and add your test recipients there.

Option 2: Environment variable

Set a global test recipient in .env:

MAILBINO_TEST_RECIPIENT=developer@company.com

This sends test_recipient on every API call. Combined with test mode on the app, all emails land in your inbox.

The environment variable only selects the recipient. It never enables test mode. When test mode is disabled in the Mailbino dashboard, Mailbino sends to the real recipient.

Option 3: Per-message

// Via mail headers
'X-Mailbino-Test-Recipient' => 'developer@company.com'

// Via direct API
Mailbino::send([
    // ...
    'test_recipient' => 'developer@company.com',
]);

Webhooks

Set the signing secret shown in the Mailbino app settings:

MAILBINO_WEBHOOK_SECRET=whsec_xxxxxxxxxxxx

Verify the raw request body before processing an event:

use Mailbino\Laravel\Webhooks\WebhookVerifier;

$event = app(WebhookVerifier::class)->verify(
    $request->getContent(),
    $request->headers->all(),
);

The verifier checks the signature, rejects stale requests and returns the decoded payload. The default timestamp tolerance is 300 seconds and can be changed with MAILBINO_WEBHOOK_TOLERANCE.

Error Handling

use Mailbino\Laravel\MailbinoException;

try {
    Mailbino::send([...]);
} catch (MailbinoException $e) {
    $e->statusCode;  // 422
    $e->apiError;    // "Domain not verified."
    $e->apiMessage;  // "The sender domain for..."
}

License

MIT

mailbino/laravel 适用场景与选型建议

mailbino/laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.8k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「email」 「laravel」 「transactional-email」 「mailbino」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mailbino/laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mailbino/laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 mailbino/laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-05