mirror of
https://github.com/marceloeatworld/plunk-laravel.git
synced 2026-10-27 21:01:10 +00:00
Laravel mail transport for Plunk API with attachments, event tracking, email verification, templates and self-hosted support
https://useplunk.com
- PHP 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| config | ||
| src | ||
| tests | ||
| composer.json | ||
| composer.lock | ||
| LICENSE.md | ||
| phpunit.xml.dist | ||
| README.md | ||
Laravel Plunk
#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('[email protected]')->send(new WelcomeMail());
Attachments, CC, BCC, and reply-to are all supported:
Mail::to('[email protected]')
->cc('[email protected]')
->bcc('[email protected]')
->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('[email protected]', 'Welcome', '<h1>Hello!</h1>', [
'from' => '[email protected]',
'name' => 'Your App',
'reply' => '[email protected]',
]);
// Send with a Plunk template
Plunk::sendTemplate('[email protected]', 'tmpl_welcome', [
'name' => 'John',
'action_url' => 'https://app.example.com/verify',
]);
Event Tracking
Track events to trigger automations and segment contacts:
Plunk::trackEvent('[email protected]', 'signed_up', [
'plan' => 'pro',
'source' => 'landing_page',
]);
Email Verification
Verify email addresses before sending:
$result = Plunk::verifyEmail('[email protected]');
if ($result['data']['valid']) {
// Email is valid
}
Multiple Recipients with Names
Plunk::sendEmail(
[
'[email protected]',
['name' => 'Bob Smith', 'email' => '[email protected]'],
],
'Team Update',
'<p>Hello team!</p>',
);
Attachments (Direct API)
Plunk::sendEmail('[email protected]', 'Your Invoice', '<p>Attached.</p>', [
'from' => '[email protected]',
'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.