mograine/laravel-sendinblue-template

A Laravel 7/8/9 service provider, facade and config file for the SendinBlue's API v3 official PHP library.

v1.0.3 2022-09-12 12:21 UTC

This package is auto-updated.

Last update: 2024-04-12 15:52:39 UTC


README

Latest Version on Packagist Total Downloads License

The package simply provides a Laravel service provider, facade and config file for the SendinBlue's API v3 official PHP library. https://github.com/sendinblue/APIv3-php-library

It also allow to simply send a laravel notification using a SendInBlue transactional template.

Installation

You can install this package via Composer using:

composer require mograine/laravel-sendinblue-template-template

Configuration

You need to publish the config file to app/config/sendinblue.php. To do so, run:

php artisan vendor:publish --tag=sendinblue.config

Now you need to set your configuration using environment variables. Go the the Sendinblue API settings and add the v3 API key to your .env file.

SENDINBLUE_API_KEY=xkeysib-XXXXXXXXXXXXXXXXXXX
SENDINBLUE_EMAIL=defaultEmail
SENDINBLUE_NAME=defaultName

Usage

This package provide a built-in notification channel to send transactional template emails.

To test it, create a new notification using the php artisan make:notification command.

Example of usage :

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Mograine\Sendinblue\SendinblueMailTemplateChannel;
use Mograine\Sendinblue\TemplateMessage;

class NewOfferNotification extends Notification
{
    use Queueable;

    public function via($notifiable)
    {
        return [ SendinblueMailTemplateChannel::class ];
    }

    public function toMailTemplate($notifiable): TemplateMessage
    {
        $templateId = 1;
        $templateMessage = new TemplateMessage($templateId);
        $templateMessage->attribute('USER_EMAIL', $notifiable->email);
        return $templateMessage;
    }
}

You can also get any V3 SendInBlue API using the built-in getAPI method :

use Mograine\Sendinblue\SendinblueApiEnum;
use Mograine\Sendinblue\Facades\Sendinblue;

// We first get the API we want
$transactionalApi = Sendinblue::getApi(SendinblueApiEnum::TransactionalEmailsApi);

// We can then easily use it, example :
$transactionalApi->deleteBlockedDomain('exampleSendinblueDomain.com');

Be sure to visit the SendinBlue official documentation website for additional information about the API.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

License

license. Please see the license file for more information.