May 17, 2018

How to Set up and Track a Simple Customer Referral Program using the Sendinblue API

Reading time about 15 min

Setting up a customer referral program is one of the best ways to massive organic growth. This article shows you how to create this type of program with the help of Sendinblue’s API.

A couple of weeks ago, we had an interesting guest post on our French blog from a member of the Growth Team at ListFlow, an early-stage startup developing a SaaS tool for contact list cleaning, contact data enrichment, and lead management.

The article discusses how the ListFlow team implemented a customer referral program using the Sendinblue API and marketing automation feature.

We didn’t want our English-speaking audience to miss out on the massive potential of customer referral marketing, so we decided to adapt the content to English and publish this article.

Why implement a customer referral program?

One of the keys to rapidly growing a business is solving the puzzle known as referral marketing.

If you want to get the most potential out of your customer referrals, you need to create viral loops within your product or user experience. This essentially entails demonstrating value to your customers and trying to generate enough excitement for them to share it with other people from their network in your target audience.

One of the most common referral marketing techniques is the use of customer referral programs.

Customer referral programs can yield absolutely massive growth in a short period of time. One of the greatest examples of this is Dropbox:

dropbox customer referral program

Dropbox famously creates a customer referral program that offered users up to 16GB of free cloud storage for referring their friends.

Referring users were awarded storage in increments of 250MB (now 500) for each new user they successfully refer. The referred user also received 250MB of storage, which provided even more encouragement to refer friends, while also lowering the bar for referred users to sign up.

As a result of this customer referral program, Dropbox grew from 100,000 users to 4,000,000 users in just over a year! That is an insane rate of growth — no matter how you look at it.

Creating your own customer referral program with Sendinblue

You should have a good understanding of the value that referral marketing can provide for growing companies. Now, let’s go over how you can achieve the same viral growth for your business by creating a customer referral program with Sendinblue.

Every referral program rests on two key factors:

  • The invitation or referral of new clients through word of mouth from existing clients (let’s call them the “referrers”)
  • The compensation for referrers to incentivize their participation in the referral program

To implement this type of customer referral program in Sendinblue using ListFlow’s system, you’ll need to set up five things:

  • A Sendinblue account with a contact list to store information from referrers and invited contacts
  • A form through which a referrer can submit contact information of the friends they want to invite
  • A page that uses PHP to handle the data submitted through the form and update the Sendinblue list via the API
  • Referral email templates created in Sendinblue that will be sent to the referrer and the invited contacts
  • Sendinblue marketing automation workflows that are triggered to send the referral emails

To avoid information overload, we’ll assume that you already have a Sendinblue account. This system can be implemented with any level of Sendinblue accounts, including free accounts.

Create a free account with Sendinblue today >>

Clean and enrich your contact lists with Listflow

ListFlow is a simple tool to help you identify invalid phone numbers and email addresses, add dozens of additional data attributes to your contact data, and score the quality of each of your leads at great scale.

500 free credits every month

Step 1: Create the customer referral form

This form doesn’t need to be complicated. All you need is a simple page that sends the submitted contact information of the invited user (as well as that of the referrer) to the backend.php page. This backend page does all the work of updating your Sendinblue contact database.

There are several ways that you can retrieve the email address of your referrers (e.g. retrieve the email address of a logged in user from your user database using their ID).

In the case of ListFlow, they decided to retrieve the referrer’s email address by passing it in the page url address with the parameter “referrer.”


Using link parameters is nice because it allows for rapid testing, and it also makes it easier to share referral links.

Step 2: Assign a contact list in Sendinblue to store invited contacts

Your list of invited contacts is the same as any other list that you might have in your database. Just create a list and name it something you’ll be able to remember. Also, be sure to note the list ID number that appears next to the list name in the Sendinblue list drop-down menu.

sendinblue list id

The other important step you will need to take is creating two new contact attributes in your Sendinblue database:

  • REF: The first (REF), allows you to keep track of the email address of the customer who referred each contact
  • INV: The second (INV), allows you to know how many invitations a referrer has successfully sent out

Add these attributes to your Sendinblue list on this page:

add contact attributes in Sendinblue

Every time a referrer submits an email address in the referral form (from step 1), the invited contact’s email address is added to your referral list as a new contact. Within the newly created contact record for the invited contact, the referrer’s address is added under the REF attribute.

For example, sends his first invite to through your referral form. This will cause to be added to your referral list in Sendinblue, and the REF attribute for will include the email address of the referrer (i.e.

contact list for customer referral program

After that, the INV attribute for the referrer is increased by one. Using the example from above, that means the INV attribute for would be increased to 1 (since this was his first referral invitation).

all contacts

Looking at our master contact list, you can see that the referred contact was successfully added and the INV attribute was properly updated for the referrer.

Step 3: Connect to the Sendinblue API

To implement this customer referral program, you’ll need to use the Sendinblue API (v3) to interact with your contact lists and send the referral emails.

Using the Sendinblue API with the PHP client is very easy. All you have to do is download the library and connect to it using these three lines of code that are already included in our backend.php file:

$api_instance = new Sendinblue\Client\Api\ContactsApi();

Note that we included the API key as a variable ($API_key). You will have to set the variable $API_key equal to your own API key at the top of backend.php so that you can connect to your own Sendinblue account.

Find your Sendinblue API key here:

Download the latest version of the Sendinblue API v3 PHP library here:

Remember: You still need to replace the parameters at the top of backend.php with the proper references that apply to your account. Update the file path to the proper file location in which you have stored the Sendinblue PHP library and set the variables $API_key and $list_id to your own account’s v3 API key and the correct list ID for the list you set up in step 2.

Overall, the backend.php page functions like this:

  • Retrieves the email addresses for the referrer and the invited contact
  • Verifies that the invited email address hasn’t already been registered in your referral list
  • If the contact has not been previously invited already, they are added to the list along with the email address of the referrer in the REF field
  • The INV attribute for the referrer is updated to reflect the new referral

Feel free to study the code, which has been commented and developed for easier comprehension.

Note that although the function die() isn’t generally recommended for use as it makes error handling difficult, it was used in this program for the sake of simplifying the code. Instead, ListFlow used a multilingual error handling system that returns JSON logs, allowing the page to be called by AJAX requests.

Step 4: Set up your marketing automation workflows in Sendinblue

To summarize our progress up until now, we have essentially created an automated directory containing all of the referrers and their newly invited contacts saved in the form of a Sendinblue contact list.

Additionally, we also have the number of successful referrals that each referrer has made included in this list.

Now comes the fun part: following up with all of these contacts by email. Thankfully, Sendinblue makes this extremely easy.

For this process, we’ll need to send two separate emails:

  • An invitation or referral email (for people who have been invited for the referrers)
  • A congratulations email (for referrers who reach a certain number of referrals)

The first step in sending these out is creating the templates for each of these and saving them in Sendinblue.

Step 4.1: Create templates for your referral email and congratulations email

We’ll start by creating the referral email template ( that will be sent to contacts who were invited by one of the referrers through your customer referral form.

To help increase email deliverability, it’s a good idea to create a plain text email using pure HTML in the text editor rather than using an HTML design with our Drag & Drop editor. You should also insert the Sendinblue variable {REF} to include their referring friend’s email address to notify them that your message is not a random SPAM message.

Here is a very basic example of a referral email template:

Hi there!

Do you like Mexican food? Your friend {REF} told us that you might! Come check us out sometime! See you soon!

Once you’ve created the referral email template, just follow the same process for creating the congratulations email template and save them both in your Sendinblue account.

Step 4.2: Send your emails with marketing automation

Now it’s time to use the data that we’ve gathered in the customer referral list to trigger marketing two automation workflows. These workflows will then send the email templates that created in the previous part of this step.

Step 4.2.1: Sending the referral email

Navigate yourself to the “Automation” tab in your Sendinblue account. Then, click on the blue button that says “create a new workflow”.

From here, you’ll have the option to choose what type of workflow you want to create. For our purposes, you’ll want to select the “Custom Workflow” option at the top left. From there you can enter a name and description for your workflow, then get started.

The first step to creating a marketing automation workflow in Sendinblue is choosing your entry point. This is the “trigger” that initiates the sequence of tasks to be completed by your workflow.

The goal of our invitation email is to be sent to referred contacts once they are submitted via the customer referral program form on index.php. This can be achieved by simply choosing the event of a contact being added to a list as our entry point.

You can find this option by clicking “Add an entry point,” then selecting “Contact Details,” and finally choosing “A contact is added to a list” from the newly-expanded options.

referral contact list entry point

After that, choose the list that you have designated as your referral contacts list. In our example, we use the list name, “Customer Referral Program.” Once you’ve chosen the right list, click “OK.”

Now you’ll be taken to the normal workflow creation screen. You’ll see that your entry point has already been established. Now, you’ll need to add the next action in the workflow: sending your emails.

Click on the “+” button below your entry point to add the next step. Then, select “send an email” from the list of options. From there, you can select the name of the email template that you created earlier for the invitation email (we used the name customerReferralProgram-Invitation).

After clicking “OK,” you’ll have finished creating the workflow.

referral email automation workflow

Click “Done,” then “Activate Workflow” and you should be good to go! Now each time a new contact is added to your referral list, they’ll receive your invitation email automatically.

Step 4.2.2: Sending the congratulations email

The last, but crucial, step in creating a customer referral program is setting up the congratulations or follow-up email. This message will be sent to your referrers once they refer a certain amount of people.

To do this, we will follow a similar process that we used for the invitation email. But, instead of using the action of being added to a list as our trigger, we will utilize the INV attribute.

To do this, create a new marketing automation workflow and select “Contact Details” >> “Contact attributes condition” as your entry point.

You will then see a window that lets you choose which attribute you want to use for the conditional trigger. From there, you can define the actual condition to be applied to this attribute in order to start the workflow.

As mentioned earlier, we will be using the INV attribute. In our example, we chose the condition “greater than 4,” so that we could send an email to any customer once they refer 5 people.

Setting automation condition to number of referrals

After setting the entry point, add a step to send the email and your workflow will be ready to go!

congratulations email workflow

If you want, you can always add more steps to the workflow. For example, if you want to provide different rewards for customers once they refer 1, 5, and 10 people, you can do this by creating separate email templates and adding the necessary steps and conditions in your workflow.


Hopefully, this system gives you a basic understanding of how you can create a referral marketing program for your business.

Of course, this is just a basic solution with a number of areas that could be improved or tweaked to better fit your needs.

For example, you can use the md5() function in PHP to encrypt the email addresses in the REF column for better security.

Also, as we mentioned at the end of the previous section, you can add more creativity to the reward structure for your referrers. These incentives have a huge effect on customer engagement in your referral program, so it’s a good idea to test out some different ideas.

One way to do this would be to create a tiered reward structure via email like we mentioned above. Another example would be adding a step in your automation workflow that calls a webhook on your site to give the referrer a special discount or coupon code.

For optimal results, you should choose whatever you think will resonate most with your customers. Then, keep trying new ideas until you have a system that really works well.

Ready to find your marketing zen?

Take the stress out of your work day with a solution that’s built for you!

Get started free