yieldstudio / laravel-mailjet-notifier
Easily send Mailjet transactional email and sms with Laravel notifier.
Installs: 4 107
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 2
Type:plugin
Requires
- php: ^8.0
- illuminate/database: ^9|^10
- illuminate/support: ^9|^10
- mailjet/mailjet-apiv3-php: ^1.5
Requires (Dev)
- ciareis/bypass: ^1.0
- friendsofphp/php-cs-fixer: ^3.8
- orchestra/testbench: 7.*|8.*
- pestphp/pest: ^1.21
- phpunit/phpunit: ^9.1
README
Easily send Mailjet transactional email and sms with Laravel notifier.
If you're just looking for a mailjet mail transport, check out mailjet/laravel-mailjet
Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.
Installation
composer require yieldstudio/laravel-mailjet-notifier
Configure
Just define these environment variables:
MAILJET_APIKEY= MAILJET_APISECRET= MAILJET_SMSTOKEN= MAIL_FROM_ADDRESS= MAIL_FROM_NAME= MAILJET_SMS_SENDER= MAILJET_DRY=true|false
Make sure that MAIL_FROM_ADDRESS is an authenticated email on Mailjet, otherwise your emails will not be sent by the Mailjet API.
MAILJET_SMS_SENDER should be between 3 and 11 characters in length, only alphanumeric characters are allowed.
When the dry mode is enabled, Mailjet API isn't called.
You can publish the configuration file with:
php artisan vendor:publish --provider="YieldStudio\LaravelMailjetNotifier\MailjetNotifierServiceProvider" --tag="config"
Usage
Send email
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use YieldStudio\LaravelMailjetNotifier\MailjetEmailChannel; class OrderConfirmation extends Notification { public function via(): array { return [MailjetEmailChannel::class]; } public function toMailjetEmail($notifiable): MailjetEmailMessage { return (new MailjetEmailMessage()) ->templateId(999999) // Replace with your template ID ->to($notifiable->firstname, $notifiable->email) ->variable('firstname', $notifiable->firstname) ->variable('order_ref', 'N°0000001'); } }
Send sms
<?php namespace App\Notifications; use Illuminate\Notifications\Notification ;use YieldStudio\LaravelMailjetNotifier\MailjetSmsChannel; use YieldStudio\LaravelMailjetNotifier\MailjetSmsMessage; class ResetPassword extends Notification { public function __construct(protected string $code) { } public function via() { return [MailjetSmsChannel::class]; } public function toMailjetSms($notifiable): MailjetSmsMessage { return (new MailjetSmsMessage()) ->to($notifiable->phone) ->text(__('This is your reset code :code', ['code' => $this->code])); } }
Unit tests
To run the tests, just run composer install
and composer test
.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail contact@yieldstudio.fr instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.