Email variables are now showing in the send email, send through the API

Hi,

I’m having trouble with variables not rendering in the emails sent via Brevo.

Here’s the relevant part of the PHP request:

        $data = [
            'sender' => [
                'name' => self::RECIPIENT_NAME,
                'email' => self::RECIPIENT_EMAIL
            ],
            'to' => [[
                'email' => self::RECIPIENT_EMAIL,
                'name' => self::RECIPIENT_NAME
            ]],
            'subject' => "New contact form request: " . $subject,
            'templateId' => $templateId,
            'params' => [
                'name' => $name,
                'email' => $email,
                'subject' => $subject,
                'question' => $question
            ]
        ];

        $client = new Client();

        try {
            $response = $client->request('POST', 'https://api.brevo.com/v3/smtp/email', [
                'headers' => [
                    'api-key' => $apiKey,
                    'Accept' => 'application/json',
                    'Content-Type' => 'application/json',
                ],
                'json' => $data,
            ]);

I’ve confirmed that the name, email, subject, and question variables are populated correctly in PHP.

Here’s what the received emails look like:

The HTML in the Brevo editor looks like this:

										<p style="margin: 0;">Name: <span title="{{ name }}" contenteditable="false" data-placeholder="name" class="placeholder rte-personalized-node fr-deletable">name</span></p>

										<p style="margin: 0;">Email: <span title="{{ email }}" contenteditable="false" data-placeholder="email" class="placeholder rte-personalized-node fr-deletable">email</span></p>

										<p style="margin: 0;">Subject: <span title="{{ subject }}" contenteditable="false" data-placeholder="subject" class="placeholder rte-personalized-node fr-deletable">subject</span></p>

										<p style="margin: 0;">Question: <span title="{{ question }}" contenteditable="false" data-placeholder="question" class="placeholder rte-personalized-node fr-deletable">question</span></p>
									</td>

From other examples I’ve seen, passing the variables through the params array like this should be enough:

      'params' => [
                'name' => $name,
                'email' => $email,
                'subject' => $subject,
                'question' => $question
            ]

Yet the values aren’t rendering in the email—only the placeholder labels show up.

Do you have any idea what might be going wrong?

Thanks in advance!

I can’t upload 2 images, so here is the second image.

This is what the template looks like in the Brevo editor

Hi, and welcome in Brevo Community !

I’m not entirely sure, but it seems you need to add an « environment » information (I don’t know how to call that) before the name of each parameter.
For exemple, in my HTML content I send {{ params.name }} when the variables were sent in « Params » section.
If I want to use variables from the Brevo contact, I send {{ contact.NAME }}.

Hope it helps

1 Like