Skip to content

augustinfla/sendinblue-api-bundle

 
 

Repository files navigation

SendinBlue Symfony Bundle

This is SendinBlue provided API V2 Symfony Bundle. It implements the various exposed APIs that you can read more about on https://apidocs.sendinblue.com.

Prerequisites

This version of the bundle requires Symfony 2.x OR 3.x.

Installation

Download SendinBlueApiBundle using composer

Add SendinBlueApiBundle in your composer.json:

        "require": {
            "sendinblue/sendinblue-api-bundle": "2.0.*"
        }
    }```

Now tell composer to download the bundle by running the command:

```bash
$ composer update

OR

Simply install by running below command

$ composer require "sendinblue/sendinblue-api-bundle"

Composer will install the bundle to your project's vendor/sendinblue directory.

Enable the Bundle

In the kernel app/AppKernel.php:

<?php

public function registerBundles()
{
    $bundles = array(
        // ...
        new SendinBlue\SendinBlueApiBundle\SendinBlueApiBundle(),
    );
}

Add SendinBlue Api key

In your app/config/config.yml:

sendin_blue_api:
    api_key: <Your access key>
    # Our library supports a timeout value, which is an optional parameter, default is 30,000 MS ( 30 secs )
    timeout: 5000

Usage

The API is available with the sendinblue_api service. To access it, add in your controller (or elsewhere):

<?php
$sendinblue = $this->get('sendinblue_api');

Example

Get your account information

<?php
$sendinblue = $this->get('sendinblue_api');

$result = $sendinblue->get_account();
// var_dump($result);

To send transactional email

<?php

use SendinBlue\SendinBlueApiBundle\Model\TransactionMailDataModel;

$sendinblue = $this->get('sendinblue_api');

$data = new TransactionMailDataModel();
$data->setTo(array("to@example.net"=>"to whom!"))
	->setCc(array("cc@example.net"=>"cc whom!"))
	->setBcc(array("bcc@example.net"=>"bcc whom!"))
	->setReplyToEmail("replyto@email.com")
	->setReplyToName("reply to!")
	->setFromName('From me')
	->setFromEmail('from@email.com')
	->setSubject('My subject')
	->setText('This is the text')
	->setHtml('This is the <h1>HTML</h1><br/>
                            This is inline image 1.<br/>
                            <img src=\"{myinlineimage1.png}\" alt=\"image1\" border=\"0\"><br/>
                            Some text<br/>
                            This is inline image 2.<br/>
                            <img src=\"{myinlineimage2.jpg}\" alt=\"image2\" border=\"0\"><br/>
                            Some more text<br/>
                            Re-used inline image 1.<br/>
                            <img src=\"{myinlineimage1.png}\" alt=\"image3\" border=\"0\">')
    ->setAttachment(array())
    ->setHeaders(array("Content-Type"=> "text/html; charset=iso-8859-1","X-param1"=> "value1", "X-param2"=> "value2","X-Mailin-custom"=>"my custom value", "X-Mailin-IP"=> "102.102.1.2", "X-Mailin-Tag" => "My tag"))
    ->setInlineImage(array("myinlineimage1.png" => "your_png_files_base64_encoded_chunk_data","myinlineimage2.jpg" => "your_jpg_files_base64_encoded_chunk_data"));

// This will validate data model and throw an exception when it is not valid
$response = $sendinblue->send_email($data);

// validateResponse() will check the response and throw an exception when it fails
$sendinblue->validateResponse($response);

// Shorter way how to write it
// $sendinblue->validateResponse($sendinblue->send_email($data));

To send transactional email template

<?php

use SendinBlue\SendinBlueApiBundle\Model\TransactionalTemplateMailDataModel;

$sendinblue = $this->get('sendinblue_api');

$data = new TransactionalTemplateMailDataModel();

$data->setId(2)
	->addTo('to-example@example.net')
	->addTo('to2-example@example.net')
	->setCc('cc-example@example.net')
	->setBcc('bcc-example@example.net')
	->setReplyTo('replyto-example@example.net')
	->setAttr(array("EXPEDITEUR"=>"His name","SUBJECT"=>"This is my subject"))
	->setAttachmentUrl('')
	->setAttachment(array("myfilename.pdf" => "your_pdf_files_base64_encoded_chunk_data"))
	->setHeaders(array("Content-Type"=> "text/html;charset=iso-8859-1", "X-param1"=> "value1", "X-param2"=> "value2", "X-Mailin-custom"=>"my custom value","X-Mailin-tag"=>"my tag value"));

$sendinblue->validateResponse($sendinblue->send_transactional_template($data));

Support and Feedback

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

If you find a bug, please submit the issue in Github directly.

As always, if you need additional assistance, drop us a note here.

About

Official Sendinblue provided API V2 Symfony 2.x & 3.x Bundle

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%