|

|  How to Integrate Sendinblue API for Email Campaigns in PHP

How to Integrate Sendinblue API for Email Campaigns in PHP

October 31, 2024

Learn to effortlessly integrate Sendinblue API in PHP and streamline your email campaigns with this step-by-step guide. Perfect for developers looking to optimize communication.

How to Integrate Sendinblue API for Email Campaigns in PHP

 

Install Sendinblue PHP Library

 

  • First, install the API client library using Composer to manage dependencies easily and ensure compatibility.
  •  

  • In your project directory, run the following command:

 

composer require sendinblue/api-v3-sdk

 

Configure API Client

 

  • Initialize the API client with your API key. You must provide the correct API key to authenticate requests.

 

require 'vendor/autoload.php';

$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_SENDINBLUE_API_KEY');
$apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi(new GuzzleHttp\Client(), $config);

 

Create the Email Campaign

 

  • Define the campaign details such as sender, subject, and content. This involves creating a new instance of the model representing the email campaign.
  • Ensure that you provide valid and appropriately formatted data for each required field.

 

$emailCampaignsApi = new SendinBlue\Client\Api\EmailCampaignsApi(new GuzzleHttp\Client(), $config);

$emailCampaign = new \SendinBlue\Client\Model\CreateEmailCampaign();
$emailCampaign->setTag('Campaign Tag');
$emailCampaign->setSender(['name' => 'Your Name', 'email' => 'your.email@example.com']);
$emailCampaign->setName('My First Campaign');
$emailCampaign->setSubject('See the latest updates');
$emailCampaign->setHtmlContent('<html><body><p>Hello, this is your newsletter!</p></body></html>');
$emailCampaign->setRecipients(['listIds' => [12, 34]]);
$emailCampaign->setScheduledAt('2023-12-01T00:00:00+00:00');

// Create the campaign
try {
    $result = $emailCampaignsApi->createEmailCampaign($emailCampaign);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling EmailCampaignsApi->createEmailCampaign: ', $e->getMessage(), PHP_EOL;
}

 

Send a Transactional Email

 

  • Use the API to send individual transactional emails, if needed. This is different from campaigns and doesn't require setting a predefined list.

 

$emailData = new \SendinBlue\Client\Model\SendSmtpEmail();
$emailData->setSubject('Hello from Sendinblue');
$emailData->setSender(['name' => 'Your Name', 'email' => 'your.email@example.com']);
$emailData->setTo([['email' => 'recipient@example.com', 'name' => 'Recipient Name']]);
$emailData->setHtmlContent('<html><body><p>This is a test email.</p></body></html>');

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

 

Handle API Responses

 

  • Manage the responses from the API to confirm whether emails were sent successfully or handle errors appropriately.
  • Incorporate logging or user notifications based on the result of your API requests to improve debugging and user interaction.

 

// Example of handling the API response
try {
    $result = $emailCampaignsApi->getCampaignStats('CAMPAIGN_ID');
    echo 'Campaign stats: ', json_encode($result), PHP_EOL;
} catch (Exception $e) {
    echo 'Error while retrieving campaign stats: ', $e->getMessage(), PHP_EOL;
}

 

Limited Beta: Claim Your Dev Kit and Start Building Today

Instant transcription

Access hundreds of community apps

Sync seamlessly on iOS & Android

Order Now

Turn Ideas Into Apps & Earn Big

Build apps for the AI wearable revolution, tap into a $100K+ bounty pool, and get noticed by top companies. Whether for fun or productivity, create unique use cases, integrate with real-time transcription, and join a thriving dev community.

Get Developer Kit Now

OMI AI PLATFORM
Remember Every Moment,
Talk to AI and Get Feedback

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI DEV KIT 2

$69.99

Make your life more fun with your AI wearable clone. It gives you thoughts, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

Your Omi will seamlessly sync with your existing omi persona, giving you a full clone of yourself – with limitless potential for use cases:

  • Real-time conversation transcription and processing;
  • Develop your own use cases for fun and productivity;
  • Hundreds of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

thought to action

team@basedhardware.com

company

careers

events

invest

privacy

products

omi

omi dev kit

personas

resources

apps

bounties

affiliate

docs

github

help