Laravel mail driver package for Mailjet and wrapper for its API
thedoctor0/laravel-mailjet-driver is a Laravel package for laravel mail driver package for mailjet and wrapper for its api.
It currently has 32 GitHub stars and 268.869 downloads on Packagist (latest version 2.1.0).
Install it with composer require thedoctor0/laravel-mailjet-driver.
Discover more Laravel packages by thedoctor0
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel mail driver for Mailjet that also wraps the
Mailjet API v3 PHP SDK — so you can
send mail through Laravel's Mail facade and reach Mailjet's REST, Send and SMS
APIs from the same package.
| Package | Laravel | PHP | |---------|-----------|------| | 2.x | 11.x – 13.x | 8.2+ | | 1.x | 9.x – 10.x | 8.0+ |
composer require thedoctor0/laravel-mailjet-driver symfony/http-client
The package registers itself automatically via Laravel's package discovery.
Grab your API key and secret from the Mailjet API keys page, then add them to your .env file and switch the mailer:
MAIL_MAILER=mailjet
MAILJET_APIKEY=your-api-key
MAILJET_APISECRET=your-api-secret
Add the credentials to config/services.php:
'mailjet' => [
'key' => env('MAILJET_APIKEY'),
'secret' => env('MAILJET_APISECRET'),
],
Register the transport in config/mail.php:
'mailers' => [
// ...
'mailjet' => [
'transport' => 'mailjet',
],
],
Note: the
fromaddress in config/mail.php must be an authorised sender configured on your Mailjet account. Manage your senders and domains here.
You can pass full MailjetClient options through config/services.php:
| Key | Used for |
|-----------------|-----------------------------------------------------------------|
| transactional | The Send API client |
| common | The client resolved behind the Mailjet facade |
| v4 | The v4 client used by some data providers (e.g. the SMS API) |
'mailjet' => [
'key' => env('MAILJET_APIKEY'),
'secret' => env('MAILJET_APISECRET'),
'transactional' => [
'call' => true,
'options' => [
'url' => 'api.mailjet.com',
'version' => 'v3.1',
'call' => true,
'secured' => true,
],
],
'common' => [
'call' => true,
'options' => [
'url' => 'api.mailjet.com',
'version' => 'v3',
'call' => true,
'secured' => true,
],
],
'v4' => [
'call' => true,
'options' => [
'url' => 'api.mailjet.com',
'version' => 'v4',
'call' => true,
'secured' => true,
],
],
],
Once the transport is configured, send mail the usual Laravel way — no Mailjet-specific code required:
use App\Mail\OrderShipped;
use Illuminate\Support\Facades\Mail;
Mail::to($user)->send(new OrderShipped($order));
Import the facade to talk to the Mailjet API directly:
use Mailjet\LaravelMailjet\Facades\Mailjet;
Send transactional email through the Send API v3.1 (the default version):
Mailjet::sendEmail([
'Messages' => [
[
'From' => ['Email' => '[email protected]', 'Name' => 'You'],
'To' => [['Email' => '[email protected]', 'Name' => 'Passenger']],
'Subject' => 'Your booking is confirmed',
'TextPart' => 'See you soon!',
'HTMLPart' => '<h3>See you soon!</h3>',
],
],
]);
// Override the API version if you need the legacy v3 payload shape:
Mailjet::sendEmail($body, ['version' => 'v3']);
Send an SMS through the SMS API v4. The SMS API authenticates with a bearer token rather than the key/secret pair — see the Mailjet docs for issuing one:
Mailjet::sendSms([
'From' => 'MyCompany',
'To' => '+33600000000',
'Text' => 'Your verification code is 123456',
]);
High-level helpers for the most common contact-management calls:
Mailjet::getAllLists($filters);
Mailjet::createList($body);
Mailjet::getListRecipients($filters);
Mailjet::getSingleContact($id);
Mailjet::createContact($body);
Mailjet::createListRecipient($body);
Mailjet::editListRecipient($id, $body);
For any endpoint without a dedicated helper, call the raw verbs with a Mailjet resource:
use Mailjet\Resources;
Mailjet::get(Resources::$Contact, $args, $options);
Mailjet::post(Resources::$Contact, $args, $options);
Mailjet::put(Resources::$Contact, $args, $options);
Mailjet::delete(Resources::$Contact, $args, $options);
Every wrapper method returns a Mailjet\Response, or throws a
Mailjet\LaravelMailjet\Exception\MailjetException on an API error. You can also
reach the underlying SDK client with Mailjet::getClient() to build fully custom
requests.
For the complete endpoint reference, see the official Mailjet API documentation.
composer test
The MIT License (MIT). Please see the license file for more information.