xammie/mailbook
Composer 安装命令:
composer require xammie/mailbook
包简介
Laravel Mail Explorer
README 文档
README
Mailbook is a Laravel package that lets you easily inspect your mails without having to actually trigger it in your application.
Installation
You can install the package via composer:
composer require --dev xammie/mailbook
Next install mailbook into your application
php artisan mailbook:install
Usage
The mailbook:install command will create a route file named routes/mailbook.php. In this file you can register your
emails.
// This will use dependency injection if your mailable has parameters Mailbook::add(VerificationMail::class); // Use a closure to customize the parameters of the mail instance Mailbook::add(function (): VerificationMail { $user = User::factory()->make(); return new VerificationMail($user, '/example/url') });
Next head over to /mailbook to preview the mailables.
Registering mails
You can both register mailables that live in App\Mails and email notifications in App\Notifications.
// Mailable Mailbook::add(VerificationMail::class); // Notification Mailbook::add(InvoiceCreatedNotification::class);
You can also use dependency injection in the closure.
// With dependency injection Mailbook::add(function (VerificationService $verificationService): VerificationMail { return new VerificationMail($verificationService, '/example/url'); }); // Without dependency injection Mailbook::add(function (): VerificationMail { $verificationService = app(VerificationService::class); return new VerificationMail($verificationService, '/example/url'); });
Sending to a user
A notification will most of the time need a user (also called notifiable in the notification class).
You can set the desired user with the ::to() method.
$user = User::factory()->create(); Mailbook::to($user)->add(WelcomeNotification::class);
If you don't need a user you can also pass an e-mail address.
Mailbook::to('example@mailbook.dev')->add(WelcomeNotification::class)
Grouping multiple mails
You can group multiple mails under the same category. This can be done using the category() and group() methods.
Mailbook::category('Invoices')->group(function () { Mailbook::add(InvoiceCreatedNotification::class); Mailbook::add(InvoicePaidNotification::class); });
To avoid having to pass the same to() to every mailable that needs it you can also use the group() method. This will
use the notifiable to every mailable inside the group.
Mailbook::to('example@mailbook.dev')->group(function () { Mailbook::add(WelcomeNotification::class); Mailbook::add(TrialEndedNotification::class); });
It is also possible to chain both category() and to() to the same group.
Mailbook::to('example@mailbook.dev') ->category('Invoices') ->group(function () { // ... });
Variants
When creating mails you might have a couple of different scenario's that you want to test for one mail, you can use variants to solve this.
// Use a closure to customize the parameters of the mail instance Mailbook::add(OrderCreatedMail::class) ->variant('1 item', fn () => new OrderCreatedMail(Order::factory()->withOneProduct()->create())) ->variant('2 items', fn () => new OrderCreatedMail(Order::factory()->withTwoProducts()->create()));
Localization
When your application supports multiple languages you need to easily preview your mails in these languages. To enable
this feature you have to add the following code to the mailbook.php config file.
'locales' => [ 'en' => 'English', 'nl' => 'Dutch', 'de' => 'German', 'es' => 'Spanish' ],
This will display a dropdown in mailbook which you can use to switch to a different language.
Using the database
Most of the time your mailables will need database models. Sometimes you will even preform queries when rendering these mailables. Mailbook can automatically rollback database changes after rendering. You can enable it in the config with.
'database_rollback' => true,
You can now safely use factories and other queries when registering your mailables.
// All database changes are rolled back after rendering the mail. Mailbook::add(function (): OrderShippedMail { $order = Order::factory()->create(); $tracker = Tracker::factory()->create(); return new OrderShippedMail($order, $tracker); });
Database rollback is disabled by default.
Sending Mails
Testing your mails outside the browser is important if you want to make sure that everything is displayed correctly. You can use Mailbook to send mails to an email address of your choice using your default mail driver. This will show a button in the top-right corner which when pressed will send the currently selected email to the specified address. You can enable this in the config:
'send' => true, 'send_to' => 'test@mailbook.dev',
Customization
You can publish the config file with:
php artisan vendor:publish --tag="mailbook-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="mailbook-views"
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
xammie/mailbook 适用场景与选型建议
xammie/mailbook 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 566.31k 次下载、GitHub Stars 达 482, 最近一次更新时间为 2022 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「mailbook」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xammie/mailbook 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xammie/mailbook 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xammie/mailbook 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Laravel developer tool: preview FCM push payloads from notifications in the browser—Mailbook-style registry (add, to, category, variants, locales), optional DB rollback, and gated test sends.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
统计信息
- 总下载量: 566.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 483
- 点击次数: 33
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-07

