Put this custom function in functions.php file or snippet plugin:
Note:
for SMS field the Accepted Number Formats is eg:
91xxxxxxxxxx
+91xxxxxxxxxx
0091xxxxxxxxxx
Default Contact Attribute
https://help.brevo.com/hc/en-us/articles/10582214160274-About-contact-attributes


6 comments
paulmaudry
Perfect,
However I’d like to know how I can include other form IDs and how I can include more fields (Firstname, Lastname…)
Thanks.
Paul
Ivan Nugraha
Hi, You could add variable key to $data eg:
$phone = isset($fields[‘form-field-phone’]) ? $fields[‘form-field-phone’] : ”;
$data = array(
’email’ => $email,
‘attributes’ => array(
‘FIRSTNAME’ => $first_name,
‘SMS’ => $phone
),
‘listIds’ => array(2), // Replace with your actual list ID
);
Here is the link for references https://developers.brevo.com/reference/createcontact
paulmaudry
Hi Ivan and thanks for the quick reply.
Unfortunately it still doesn’t work for me, here is the piece of my code snippet :
if ($formId == ‘caa0c9’) {
// Retrieve the email field value (replace ‘form-field-ecc90f’ with the actual field key)
$email = isset($fields[‘form-field-izbbrg’]) ? $fields[‘form-field-izbbrg’] : ”;
$firstname = isset($fields[‘form-field-50f355’]) ? $fields[‘form-field-50f355’] : ”;
$lastname = isset($fields[‘form-field-zvcfum’]) ? $fields[‘form-field-zvcfum’] : ”;
$phone = isset($fields[‘form-field-tluzna’]) ? $fields[‘form-field-tluzna’] : ”;
// Proceed if the email is not empty
if (!empty($email)) {
// API URL for Brevo (Sendinblue) Contact creation
$api_url = ‘https://api.brevo.com/v3/contacts’;
// API Key for Brevo (replace ‘YOUR_API_KEY’ with your actual API key)
$api_key = ‘xxxxx’;
// Data to be sent to Brevo
$data = array(
’email’ => $email,
‘attributes’ => array(
‘FNAME’ => $firstname,
‘LNAME’ => $lastname,
‘SMS’ => $phone,
),
‘listIds’ => array(10), // Replace with your actual list ID
‘updateEnabled’ => true, // Set to true if you want to update the contact if they exist
‘doubleOptinActivation’ => true, // Enable double opt-in
);
I don’t know what I’m doing wrong, if you could take a look.
Thanks a lot.
Paul
Ivan Nugraha
Hi, i updated the code with the log so you can find a clue if it still doesnt work for you. And please see phone number accepted format.
Ivan Nugraha
Hi, it seems correct, i will take a look at that issue. Cheers
christoph
Love it, thank you Ivan!