Overview
In this article I will cover how I send transactional emails using Brevo (formerly SendInBlue) email service.
We will cover for what purposes I send such emails, how to send transient emails programmatically, how to create templates for such emails.
As an example, we will create a template for cart abandoned email and learn how to send such emails via PHP code.
What are Transactional Emails
Generally speaking, by 'transactional emails' most often they are talking about all types of automatic emails such as
- Order Confirmations
- Account Verification Emails
- Invoice/Receipt Emails
- Abandoned Cart Emails
and so on.
So it is all types of emails that are sent automatically and have some common template.
I personally use Brevo to send only one type of transactional emails - Abandoned Cart Emails. I send such emails for users that open the checkout pop-up for Advanced Woo Search and Advanced Woo Labels plugins but don't finish the purchase. Such abandoned emails are sent to such users after 60 minutes.

Getting Started with Brevo
Register Account
So first of all to start sending transactional emails with Brevo, we need to create an account on this platform.
Simply go to https://www.brevo.com/ and register your account. You can start with the free plan - it offers 300 emails/day to send - more than enough for the start. I personally send around 10 transactional emails per day.

About Email Parameters
Before starting to create our first email template, we need to learn something about Brevo transactional emails.
The most powerful part of such emails is that you can add any dynamic text value inside them such as user name, email, job title, or any other custom data that was sent via code when triggering email send. In Brevo, this is called text attributes.
We will cover custom email attributes sending a bit later, for now, just keep in mind that it is possible to send any custom values that you need.
For clarity, here is a list of custom parameters that I'm using.
- EMAIL - user email address
- FIRSTNAME - user first name
- LICENSE_TYPE - plugin license type (for abandoned emails it is the license they started to purchase)
- PRICE - plugin price
- PLUGIN_NAME - plugin name
Keep in mind that your list can be very different from this one, but in this example of abandoned emails, we will use only this limited list of text variables.
To use such custom attributes, you don't need to add them manually to Brevo settings - we will just specify them inside the email template and later send them via our custom script.

Creating Email Template
Now it is time to create our first email template. Log-in to your Brevo account and go to Transactional -> Templates page.
Here we need to create our template for transactional email.
Click Create Template -> Email template. On next page set template name, subject line, preview text and from parameters.

You can use plain text and attributes here.
As an example here is how my template for abandoned email is look like.

When you finished with this first step - click on Next Step button to start creating email design.
You can start from scratch or use one of pre-defined templates as boilerplate. It is up to your choice.

I won't stop on this step for a long time - creating such email design is pretty simple and intuitive. The main part here is to use previously described text attributes.
As an example here is my design for abandoned email template:

As seen design here is very simple - some heading with user name at the top, text that mentioned plugin name that user add to its cart along with some mention that user can finished his purchase right now.
At the bottom of the email we see all product information that comes from custom text attributes.
Complete Your Checkout button also has a link that comes from custom attributes. By clicking on it user we be redirected to checkout page with needed product type.
When you are finished with creating email design - click Save & Activate button to activate your custom email template.
Important part - go to the list of your email templates and remember your newly create email template ID. It can be found just near template name. You will need it in the next chapter.

Creating Brevo API key
Lastly we need to create Brevo API key in order to be able to send transactional emails.
To do that go to your Brevo account, click profile button at the top right corner and select SMTP & API.
On the next page choose API Keys tab and click Generate a new API key button. Generate your API key and save it somewhere - we will need it very soon.

Sending Emails with PHP Script
Now, after we create a Brevo account, email template and API key it is time to learn how to send such transactional email via custom php script.
Why PHP? I use it in my daily job and it is a language that I familiar with. It is also possible to send such email with any other program language, but in this chapter we will cover how to use only PHP for such task.
Good news is that Brevo already has some php library for email sending. You can find it here.
Install it in any preferred way. We will not cover this part as it is very standard one and just cover how to create a custom script for sending custom email.
Without more words here is a php script that you can use for transactional email sending:
include_once( THEME_DIR . '/vendor/autoload.php' ); define('SENDINBLUE_API', '{MY_API_KEY}' ); class UP_Brevo { /** * Email client config * @var object */ public $config; /** * Initialize * @param $data */ function __construct() { $config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', SENDINBLUE_API); $config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('partner-key', SENDINBLUE_API); $this->config = $config; } /* * Send transactional email */ public function send( $date = array() ) { $apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi( new GuzzleHttp\Client(), $this->config ); $sendSmtpEmail = new \SendinBlue\Client\Model\SendSmtpEmail($date); try { $result = $apiInstance->sendTransacEmail($sendSmtpEmail); } catch (Exception $e) { $result = false; error_log( 'SENDINBLUE API: Exception when calling AccountApi->getAccount: ' . $e->getMessage() ); } return $result; } }
This code loads Brevo library and create a class UP_Brevo that we can use for emails sending. Please note that you need to replace {MY_API_KEY} with your actual Brevo API key.
Now all is ready for email sending.
In this article we won't cover how we can get information about abandoned carts - it is a topic for my next article. For now lets assume that we know user email, name and product data that he wanted to purchase. Keeping all this in mind just use following code.
$sendSmtpEmail = array(); $sendSmtpEmail['sender'] = array( 'name' => '{YOUR_COMPANY_NAME}', 'email' => '{YOUR_COMPANY_EMAIL}', ); $sendSmtpEmail['to'] = array(array( 'email'=> '{USER_EMAIL}', "name"=> '{USER_NAME}', )); $sendSmtpEmail['templateId'] = {EMAIL_TEMPLATE_ID}'; $sendSmtpEmail['params'] = array( 'FIRSTNAME' => '{USER_NAME}', 'PLUGIN_NAME' => '{PRODUCT_NAME}', 'WEBSITE' => '{PRODUCT_WEBSITE}', 'SUPPORT_EMAIL' => '{YOUR_COMPANY_EMAIL}', 'CHECKOUT_LINK' => '{PRODUCT_CHECKOUT_LINK}', 'PRICE' => '{PRODUCT_PRICE}', ); $sendinblue = new UP_Brevo(); $sendinblue->send($sendSmtpEmail);
As seen here is plenty of field that your need to fill. Take note to {EMAIL_TEMPLATE_ID} - it is Brevo custom email template ID that we mentioned previously.
Fill all other field like your company data, user and product data and run the script. Transactional email must be immediately be send.
Conclusion
Transactional emails are a powerful way to engage users and recover potential lost sales, particularly for abandoned cart scenarios. By leveraging Brevo's email service and a custom PHP script, you can create automated, personalized email campaigns that reach out to users at the right moment.
The key steps we've covered include:
- Setting up a Brevo account
- Creating custom email templates with dynamic attributes
- Generating an API key
- Implementing a PHP script to send transactional emails
While this guide provides a solid foundation, there's still more to explore, such as advanced webhook integrations and more sophisticated abandoned cart tracking. The potential for improving user engagement through well-crafted transactional emails is significant.
What Next
So we learned how to create and send transactional emails using Brevo email service and some custom PHP code. But this article covers only part of the problem.
We know how to trigger email sending, but how to know when a user's cart was abandoned? How to get user parameters like name, email, product type that he is trying to purchase?
All these questions weren't covered in this article as they are a bit complex and can be covered in a separated post.
I personally is using FastSpring for payments and receive abandoned carts event throw its webhooks. Then I send abandoned email as described in this article. Such webhooks integration is worth to mention in separated article and I will cover it for sure. Stay tuned!