thedoctor0 / laravel-mailjet-driver
Laravel mail driver package for Mailjet and wrapper for its API
Fund package maintenance!
thedoctor0
www.paypal.me/thedoctor0
Installs: 164 577
Dependents: 1
Suggesters: 0
Security: 0
Stars: 32
Watchers: 6
Forks: 7
Open Issues: 0
Requires
- laravel/framework: ~5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- mailjet/mailjet-apiv3-php: ^1.5.6|^1.5
- symfony/mailjet-mailer: ^6.0|^7.0
Requires (Dev)
- fzaninotto/faker: ~1.9|^1.5
- mockery/mockery: ~1.3
- orchestra/testbench: ~3.5|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ~6.5|^7.0|^8.0|^9.0|^10.5
README
Laravel mail driver package for Mailjet. It also serves as a wrapper for Mailjet API v3.
Installation
For Laravel 9.x and 10.x which also requires Symfony Mailer:
composer require thedoctor0/laravel-mailjet-driver symfony/http-client
In other cases:
composer require thedoctor0/laravel-mailjet-driver:1.0.4
Configuration
You can find your Mailjet API key / secret here.
Change default mail driver and add new variables to your .env file:
MAIL_DRIVER=mailjet MAILJET_APIKEY=YOUR_APIKEY MAILJET_APISECRET=YOUR_APISECRET
Add section to the config/services.php file:
'mailjet' => [ 'key' => env('MAILJET_APIKEY'), 'secret' => env('MAILJET_APISECRET'), ],
Make sure that in config/mail.php as mail sender address you are using an authorised email address configured on your Mailjet account.
Your available Mailjet email addresses and domains can be managed here.
For Laravel 7+ you also need to specify new available mail driver in config/mail.php:
'mailers' => [ ... 'mailjet' => [ 'transport' => 'mailjet', ], ],
Optional configuration
You can add full configuration for MailjetClient to the config/services.php file.
transactional
: settings to sendAPI clientcommon
: setting to MailjetClient accessible through the Facade Mailjetv4
: setting used for some DataProvider`s
'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 ] ], ],
API Wrapper usage
In order to API wrapper from this package, you first need to import Mailjet Facade in your code:
use Mailjet\LaravelMailjet\Facades\Mailjet;
Then you can use one of the methods available in the MailjetServices class.
Low level API methods:
Mailjet::get($resource, $args, $options)
Mailjet::post($resource, $args, $options)
Mailjet::put($resource, $args, $options)
Mailjet::delete($resource, $args, $options)
High level API methods:
Mailjet::getAllLists($filters)
Mailjet::createList($body)
Mailjet::getListRecipients($filters)
Mailjet::getSingleContact($id)
Mailjet::createContact($body)
Mailjet::createListRecipient($body)
Mailjet::editListrecipient($id, $body)
All method return Mailjet\Response
or throw a MailjetException
in case of any API error.
You can also get the Mailjet API client with the method getClient()
and make your own custom request to Mailjet API.
For more information please refer to the official Mailjet API documentation.