Skip to content
SANDIP ROY edited this page Mar 27, 2020 · 4 revisions

Sendinblue SMTP-Transactional Mailer

You can send transactional mail with sendinblue easily using their SMTP API. I created this class to make my work easy. You are free to use, modify according to your requirements.

How to use

Step 1. Download the class and include it in your project
Step 2. Use the class as follow-

Example 1:

use SendinBlueHelper\Mail\Mail as myMailer;

require_once 'class.mail.php';

$email = new myMailer();
$email->from('sender@domain.com', 'Sender Name'); //Required when not using template, Sender Name is optional
$email->subject('Confirmation Mail'); //Email Subject, required
$email->content('Hello, this is email content!'); //Required when not using template, Your HTML content for the email body, required
$email->send('receiver@domain.com', 'Receiver Name'); //Receiver Name is not mandatory

Example 2: Using Template

use SendinBlueHelper\Mail\Mail as myMailer;

require_once 'class.mail.php';

$email = new myMailer();
$email->template(TEMPLATE_ID); //Your template id from sendinblue dashboard
$email->params(array()); //Template parameters, if you require
$email->addTo(array(['name' => 'John Doe', 'email' => 'john@domain.com'], ['email' => 'doe@domain.com'])); //User name is not mandatory
$email->send(); //you also can add receiver here, see example 1

Note. When using template, you don't need to set sender, subject, content. These will be igonored.

Use CC/BCC

//Add cc, bcc
$email->cc('cc@domain.com'); //adding single
$email->bcc(array(['name' => 'CC User', 'email' => 'cc2@domain.com'], ['name' => 'CC User 3', 'email' => 'cc3@domain.com'])); //adding multiple

Catching Response

You can easily check the curl response Example-

//catch server response, json string
//you can pass true to get object e.g. $email->getResponse(true)
$response = $email->getResponse(); 

//Check for error
if($email->hasError())
{
//print error string
 echo $email->getError();
}

//if email is sent, check for the message id sent by sendinblue
if(!$email->hasError())
{
 echo $email->messageID();
}
Clone this wiki locally