Code Monkey home page Code Monkey logo

laravel-sendinblue's Introduction

laravel-sendinblue

Laravel's mail transport for SendinBlue

Build Status

Summary

Installation

composer require webup/laravel-sendinblue

Compatibility

Version Laravel Sendinblue Api
3.* 7.0 and above v3
2.* 5.5 - 6.* v3
1.1.* 5.5 - 6.* v2
1.0.* 5.0 - 5.4 v2

Configuration

config/mail.php

    'mailers' => [
        // ...
        'sendinblue' => [
            'transport' => 'sendinblue',
        ],
    ]

config/services.php

    'sendinblue' => [
        // api-key or partner-key
        'key_identifier' => env('SENDINBLUE_KEY_IDENTIFIER', 'api-key'),
        'key' => env('SENDINBLUE_KEY'),
    ],

.env

MAIL_MAILER=sendinblue
SENDINBLUE_KEY=your-access-key

# if you need to set the guzzle proxy config
# those are example values
HTTP_PROXY="tcp://localhost:8125"
HTTPS_PROXY="tcp://localhost:9124"
NO_PROXY=.mit.edu,foo.com

Usage in Mailable with Template Id

Using the sendinblue() method you may pass extra fields listed below. All fields are optional:

  • template_id (integer)
  • tags (array)
  • params (array)

If you want to use the subject defined in the template, it's necessary to pass the SendinBlueTransport::USE_TEMPLATE_SUBJECT placeholder in the subject(). You may as well override the subject text here. Otherwise, without the subject() method, the subject will be derived from the class name.

Mailable requires a view - pass an empty array in the view() method.

<?php

declare(strict_types=1);

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Webup\LaravelSendinBlue\SendinBlue; // <- you need this
use Webup\LaravelSendinBlue\SendinBlueTransport; // <- you need this

class MyMailable extends Mailable
{
    use Queueable;
    use SerializesModels;
    use SendinBlue; // <- you need this

    // ...

    public function build()
    {
        return $this
            ->view([])
            ->subject(SendinBlueTransport::USE_TEMPLATE_SUBJECT) // use template subject
            // ->subject('My own subject') // subject overridden
            ->sendinblue(
                [
                    'template_id' => 84,
                    'tags'        => ['offer'],
                    'params'      => [
                        'FIRSTNAME' => 'John',
                        'LINK'      => 'https://www.example.com',
                        'AMOUNT'    => '29',
                    ],
                ]
            );
    }
}

Params are accessbile in the SendinBlue template as:

  • {{ params.FIRSTNAME }}
  • {{ params.LINK }}
  • {{ params.AMOUNT }}

You may as well use param substitution in the subject field, eg.:
{{ params.FIRSTNAME }}, forgot your password?!

Note: Do not use hyphens '-' in the variable names. {{ params.FIRST_NAME }} will work properly, but {{ params.FIRST-NAME }} will fail. Source: sendinblue/APIv3-php-library#151

Regarding additional features

This library aims to provide a Laravel-compatible interface for SendInBlue along with support for template ids, tags and params.

If you need features like specific SendInBlue beta SMTP Template batching, you should directly use the official SendInBlue PHP library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.