mailifica / mailifica-laravel
Official Laravel Mail Transport Driver and SDK for Mailifica Email Infrastructure Platform
Requires
- php: >=8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^10.0 || ^11.0 || ^12.0 || ^13.0
- illuminate/mail: ^10.0 || ^11.0 || ^12.0 || ^13.0
- illuminate/notifications: ^10.0 || ^11.0 || ^12.0 || ^13.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0 || ^13.0
- symfony/mailer: ^6.0 || ^7.0 || ^8.0
- symfony/mime: ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0 || ^11.0
- phpunit/phpunit: ^10.0 || ^11.0
This package is not auto-updated.
Last update: 2026-09-01 21:59:56 UTC
README
Official Laravel integration for the Mailifica Transactional & Marketing Email Infrastructure.
โก Features
- ๐ Native Laravel Mail Transport Driver: Use
Mail::to()or Mailables directly with Mailifica. - ๐ Laravel Notification Channel: Send rich notifications via
MailificaChannelandMailificaMessage. - ๐ช Facade Support: Full access to the REST API (
Mailifica::sendEmail(),Mailifica::listDomains(), etc.). - ๐ก๏ธ Secure Webhooks: Automatic HMAC-SHA256 signature verification & event dispatching (
MailificaWebhookReceived). - โฑ๏ธ Scheduled Sending & Metadata: Native support for tags, metadata, scheduled delivery, and template rendering.
- ๐งฉ Laravel 10.x, 11.x, 12.x, and 13.x Ready: Works out of the box with modern PHP (>= 8.1).
๐ฆ Installation
Install the package via Composer:
composer require mailifica/mailifica-laravel
Publish the configuration file:
php artisan vendor:publish --tag="mailifica-config"
โ๏ธ Configuration
1. Environment Variables (.env)
Add your Mailifica credentials to your .env file:
MAIL_MAILER=mailifica MAILIFICA_API_KEY=ma_live_your_api_key_here MAILIFICA_BASE_URL=https://api.mailifica.com/v1 # Optional Webhook Secret for signature verification MAILIFICA_WEBHOOK_SECRET=whsec_your_webhook_secret
2. Configure Mailer in config/mail.php
In your config/mail.php, register the mailifica mailer:
'mailers' => [ 'mailifica' => [ 'transport' => 'mailifica', ], // ... ],
๐ Usage
1. Sending Standard Mailables (Mail::to())
Just use Laravel's standard Mail facade:
use Illuminate\Support\Facades\Mail; use App\Mail\WelcomeEmail; Mail::to('user@example.com')->send(new WelcomeEmail($user));
Or send raw emails:
use Illuminate\Support\Facades\Mail; Mail::raw('Hello from Mailifica!', function ($message) { $message->to('user@example.com') ->from('notifications@yourdomain.com', 'Acme App') ->subject('Welcome to Acme!') ->getHeaders() ->addTextHeader('X-Mailifica-Tag', 'category=welcome'); });
2. Sending via Laravel Notifications
namespace App\Notifications; use Illuminate\Notifications\Notification; use Mailifica\Laravel\Notifications\MailificaChannel; use Mailifica\Laravel\Notifications\Messages\MailificaMessage; class InvoicePaidNotification extends Notification { public function via($notifiable): array { return [MailificaChannel::class]; } public function toMailifica($notifiable): MailificaMessage { return MailificaMessage::create('Your Invoice Has Been Paid') ->from('billing@yourdomain.com') ->html('<h1>Thank you for your payment!</h1><p>Invoice #1023 is settled.</p>') ->tag('category', 'invoices') ->metadata('invoice_id', '1023') ->attachFromPath(storage_path('invoices/invoice-1023.pdf')); } }
3. Using the Mailifica Facade
Directly call the REST API from anywhere in your application:
use Mailifica\Laravel\Facades\Mailifica; // Send transactional email $response = Mailifica::sendEmail([ 'from' => 'Sender <hello@yourdomain.com>', 'to' => 'receiver@example.com', 'subject' => 'Verify your email address', 'html' => '<strong>Click <a href="...">here</a> to verify.</strong>', 'tags' => [ ['name' => 'action', 'value' => 'verification'], ], ]); // List verified domains $domains = Mailifica::listDomains(); // Retrieve email delivery status $email = Mailifica::getEmail('email_abc123');
4. Handling Inbound Webhooks
When a webhook arrives at the configured endpoint (default: /mailifica/webhook), MailificaWebhookReceived is automatically dispatched:
In EventServiceProvider (or AppServiceProvider):
use Mailifica\Laravel\Events\MailificaWebhookReceived; use Illuminate\Support\Facades\Event; Event::listen(MailificaWebhookReceived::class, function (MailificaWebhookReceived $event) { switch ($event->type) { case 'email.delivered': // $event->data contains email details logger()->info('Email delivered: ' . $event->data['id']); break; case 'email.bounced': logger()->warning('Email bounced: ' . $event->data['recipient']); break; case 'email.complained': logger()->alert('Spam complaint received for: ' . $event->data['recipient']); break; } });
๐งช Running Tests
vendor/bin/phpunit
๐ License
The MIT License (MIT). Please see License File for more information.