Sending Free Emails with SendinBlue API V3

Email has become one of the integral part of our daily process in recent years. Especially to business or corporate houses, emails are widely used for communication and marketing purposes.

In this article, we are going to learn to send emails using PHP. We will be using the service of Sendinblue API V3 to send email. We are provided with 300 emails quota per day in free plan.

Follow this video for complete guidance :

 

Download SendinBlue API V3 SDK with following command using composer

composer require sendinblue/api-v3-sdk

Source Code :

<?php

require_once('vendor/autoload.php');

$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', '{YOUR_API_KEY}');

$apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi(
    new GuzzleHttp\Client(),
    $config
);
$sendSmtpEmail = new \SendinBlue\Client\Model\SendSmtpEmail();
$sendSmtpEmail['subject'] = 'Subject';
$sendSmtpEmail['htmlContent'] = '<html><body><h1>This is a transactional email </h1></body></html>';
$sendSmtpEmail['sender'] = array('name' => 'John Doe', 'email' => '[email protected]');
$sendSmtpEmail['to'] = array(
    array('email' => '[email protected]', 'name' => 'Anonymous')
);

try {
    $result = $apiInstance->sendTransacEmail($sendSmtpEmail);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling TransactionalEmailsApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
}

 



Recommended For You

About the Author: Admin