Mailjet for Laravel
This package integrates the Mailjet API Client in Laravel.
You can access the API through Laravel service container or sending mails in Laravel's way with the new driver., (*1)
Install
This package requires version 5.1 of Laravel framework. I can't ensure the compatibility with other versions., (*2)
In your composer.json
, add this to the require
section:, (*3)
"siallez/laravel-mailjet" : "dev-master",
Run composer update
., (*4)
In config/app.php
, add this to the providers
array:, (*5)
Siallez\Mailjet\MailjetServiceProvider::class,
Setup
In order to start using the package you only need to add these environment variables in your .env
file with your Mailjet keys:, (*6)
MAILJET_APIKEY_PUBLIC=
MAILJET_APIKEY_PRIVATE=
If you want to use the driver you should also add this:, (*7)
MAIL_DRIVER=mailjet
Usage
You can access the API with dependency injection or all other available methods to resolve the Service Container. If you want to learn how to use it you can go to the official Mailjet repository., (*8)
Example:
``` php
Route::get('/mailjet', function(\Mailjet\Client $mj) {
$response = $mj->get(\Mailjet\Resources::$Contact);
if ($response->success()) {
$contact = $response->getData();
return dd($contact);
}, (*9)
return dd($response);
});, (*10)
Using the driver is as easy as setting `mailjet` as the mail driver (look at Setup). After that, you can use the regular Laravel's Mail facade and all mails will be sent with mailjet. You can find all the information about that [here](http://laravel.com/docs/5.1/mail).
Example:
``` php
Route::get('/mailjet2', function() {
$mail = Mail::raw('Text to e-mail', function ($message) {
$message->from('from@email.com')->to('to@email.com')->subject('Testing mailjet');
});
return dd($mail);
});