drese/laravel-maileroo
Composer 安装命令:
composer require drese/laravel-maileroo
包简介
Laravel wrapper and integration for Maileroo SDK - seamless mail transport and form submissions
README 文档
README
A Laravel wrapper package for Maileroo (*affiliate link) that provides seamless integration with Laravel's Mail system and form submissions. This package wraps the Maileroo SDK to make email sending simple and Laravel-friendly.
Features
- ✅ Seamless Laravel Mail integration
- ✅ Works with Mailables, Notifications, and Queued emails
- ✅ Form submission helper with auto-formatted HTML tables
- ✅ Direct SDK access when needed
- ✅ Support for CC, BCC, and Reply-To
- ✅ Attachment support
- ✅ Auto-discovery for Laravel
Requirements
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
Create a Maileroo Account
If you do not already have one, create a Maileroo Account here (*affiliate link). Once created, you will need to generate an API key and have it handy when setting up your environment variables.
Maileroo offers a generous free tier to get you going.
Installation
Install the package via Composer:
composer require drese/laravel-maileroo
Publish Configuration
php artisan vendor:publish --tag=maileroo-config
Configure Environment
Add the following to your .env file:
MAILEROO_API_KEY=your-api-key-here MAIL_MAILER=maileroo MAILEROO_TIMEOUT=30 MAIL_FROM_ADDRESS=hello@example.com MAIL_FROM_NAME="John Smith"
Update Mail Configuration
Add Maileroo to the mailers array in config/mail.php:
'mailers' => [ 'maileroo' => [ 'transport' => 'maileroo', ], // ... other mailers ],
Usage
Transactional Emails
Use Laravel's standard Mail facade with any Mailable:
use Illuminate\Support\Facades\Mail; use App\Mail\WelcomeEmail; Mail::to('user@example.com')->send(new WelcomeEmail($user));
Or send via Notifications:
$user->notify(new InvoicePaid($invoice));
Standard Mailable Example
Mailables work automatically with the Maileroo transport:
namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Mail\Mailables\Address; use Illuminate\Queue\SerializesModels; class WelcomeEmail extends Mailable { use Queueable, SerializesModels; public function __construct( public $user ) {} public function envelope(): Envelope { return new Envelope( from: new Address('welcome@example.com', 'Welcome Team'), subject: 'Welcome to Our Platform!', ); } public function content(): Content { return new Content( view: 'emails.welcome', ); } public function attachments(): array { return []; } }
Simple Email via Maileroo Facade:
use Drese\LaravelMaileroo\Facades\Maileroo; Maileroo::sendEmail([ 'from' => 'sender@example.com', 'to' => 'recipient@example.com', 'subject' => 'Hello', 'html' => '<h1>Hello World!</h1>', 'plain' => 'Hello World!', ]);
Form Submissions
The package includes a convenient form submission helper that automatically formats form data into an HTML table.
Using the Facade:
namespace App\Http\Controllers; use Illuminate\Http\Request; use Drese\LaravelMaileroo\Facades\Maileroo; class ContactController extends Controller { public function submit(Request $request) { $validated = $request->validate([ 'name' => 'required|string', 'email' => 'required|email', 'subject' => 'required|string', 'message' => 'required|string', ]); $referenceId = Maileroo::sendFormNotification( $validated, 'admin@example.com', 'New Contact: ' . $validated['subject'] ); return back()->with('success', "Message sent! Reference: {$referenceId}"); } }
Using Dependency Injection:
use Drese\LaravelMaileroo\MailerooFormService; class ContactController extends Controller { public function submit(Request $request, MailerooFormService $maileroo) { $validated = $request->validate([ 'name' => 'required', 'email' => 'required|email', 'message' => 'required', ]); $referenceId = $maileroo->sendFormNotification( $validated, 'admin@example.com', 'New Contact Form Submission' ); return back()->with('success', "Message sent! Reference: {$referenceId}"); } }
Direct SDK Access
For advanced use cases, you can access the Maileroo SDK directly.
Advanced Example with Attachments:
namespace App\Services; use Maileroo\MailerooClient; use Maileroo\EmailAddress; use Maileroo\Attachment; class EmailService { public function __construct( protected MailerooClient $client ) {} public function sendInvoice($invoice) { return $this->client->sendBasicEmail([ 'from' => new EmailAddress('billing@example.com', 'Billing Team'), 'to' => new EmailAddress($invoice->customer->email, $invoice->customer->name), 'subject' => 'Invoice #' . $invoice->number, 'html' => view('emails.invoice', compact('invoice'))->render(), 'attachments' => [ Attachment::fromFile($invoice->pdf_path, 'application/pdf') ], 'tags' => [ 'type' => 'invoice', 'customer_id' => $invoice->customer_id, ], 'reference_id' => 'invoice-' . $invoice->id, ]); } }
Scheduled Emails:
public function scheduleEmail() { return $this->client->sendBasicEmail([ 'from' => new EmailAddress('sender@example.com'), 'to' => new EmailAddress('recipient@example.com'), 'subject' => 'Scheduled Email', 'html' => '<p>This will be sent later</p>', 'scheduled_at' => date('c', strtotime('+1 day')), ]); }
Bulk Emails:
public function sendBulk() { return $this->client->sendBulkEmails([ 'subject' => 'Newsletter', 'html' => '<h1>Hello {{name}}!</h1>', 'messages' => [ [ 'from' => new EmailAddress('newsletter@example.com'), 'to' => new EmailAddress('user1@example.com'), 'template_data' => ['name' => 'John'], ], [ 'from' => new EmailAddress('newsletter@example.com'), 'to' => new EmailAddress('user2@example.com'), 'template_data' => ['name' => 'Jane'], ], ], ]); }
License
The MIT License (MIT). Please see the License File for more information.
Support
This package is provided as-is in the hope that it will benefit the Laravel community. It is offered without warranty and without commitment to ongoing support.
drese/laravel-maileroo 适用场景与选型建议
drese/laravel-maileroo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「email」 「smtp」 「laravel」 「maileroo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 drese/laravel-maileroo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drese/laravel-maileroo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 drese/laravel-maileroo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Mail libraries used by Zimbra Api
Extensible library for building notifications and sending them via different delivery channels.
The Message Submission Agent Diagnostics tool (msadiag) facilitates testing the compatibility of third party message submission agents.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
PHPMailer helper class for sending emails using SMTP
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-07