marceloeatworld/plunk-laravel
最新稳定版本:v1.0.0
Composer 安装命令:
composer require marceloeatworld/plunk-laravel
包简介
#1 Laravel mail transport for Plunk with event tracking and email verification, compatible with native PHP
README 文档
README
#1 Laravel mail transport for Plunk with event tracking and email verification, compatible with native PHP. Works with both the official Plunk service and self-hosted instances.
Requirements
- PHP 8.2+
- Laravel 10, 11, or 12
Installation
composer require marceloeatworld/plunk-laravel
Publish the config file:
php artisan vendor:publish --tag="plunk-config"
Configuration
Add the Plunk mailer to config/mail.php:
'mailers' => [ // ... other mailers 'plunk' => [ 'transport' => 'plunk', ], ],
Add to your .env:
MAIL_MAILER=plunk PLUNK_API_KEY=sk_your_secret_key
For self-hosted Plunk:
PLUNK_API_URL=https://plunk.yourdomain.com PLUNK_API_ENDPOINT=/api/v1/send
Usage
Sending Emails (Laravel Mail)
Use Laravel's mail system as usual -- emails are sent through Plunk automatically:
Mail::to('user@example.com')->send(new WelcomeMail());
Attachments, CC, BCC, and reply-to are all supported:
Mail::to('user@example.com') ->cc('manager@example.com') ->bcc('audit@example.com') ->send(new InvoiceMail());
Direct API Access (Facade)
Use the Plunk facade for direct API access:
use MarceloEatWorld\PlunkLaravel\Facades\Plunk; // Send email directly Plunk::sendEmail('user@example.com', 'Welcome', '<h1>Hello!</h1>', [ 'from' => 'hello@yourdomain.com', 'name' => 'Your App', 'reply' => 'support@yourdomain.com', ]); // Send with a Plunk template Plunk::sendTemplate('user@example.com', 'tmpl_welcome', [ 'name' => 'John', 'action_url' => 'https://app.example.com/verify', ]);
Event Tracking
Track events to trigger automations and segment contacts:
Plunk::trackEvent('user@example.com', 'signed_up', [ 'plan' => 'pro', 'source' => 'landing_page', ]);
Email Verification
Verify email addresses before sending:
$result = Plunk::verifyEmail('user@example.com'); if ($result['data']['valid']) { // Email is valid }
Multiple Recipients with Names
Plunk::sendEmail( [ 'alice@example.com', ['name' => 'Bob Smith', 'email' => 'bob@example.com'], ], 'Team Update', '<p>Hello team!</p>', );
Attachments (Direct API)
Plunk::sendEmail('user@example.com', 'Your Invoice', '<p>Attached.</p>', [ 'from' => 'billing@yourdomain.com', 'attachments' => [ [ 'filename' => 'invoice.pdf', 'content' => base64_encode(file_get_contents('/path/to/invoice.pdf')), 'contentType' => 'application/pdf', ], ], ]);
Testing
composer test
Credits
License
The MIT License (MIT). See LICENSE.md for details.
统计信息
- 总下载量: 451
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-25