• Hello i try to send entry to brevo (no integration dommage)

    but my custom code doesn’t works … i don’t understand why

    add_action(‘forminator_form_after_save_entry’, function($entry, $form) {
    // Configuration
    $form_id = 32; // My FORM
    $api_key = ‘MYAPIKEY’; // À remplacer
    $list_id = 36; //MY brevo list

    // Récupère les données du formulaire
    $meta_data = $entry->meta_data;

    error_log('Forminator Entry Meta Data (Debug): ' . print_r($meta_data, true));

    // Vérifie si la checkbox est cochée
    $checkbox_checked = isset($meta_data['checkbox-1']) && !empty($meta_data['checkbox-1']);

    if (!$checkbox_checked) {
    error_log('Brevo: Checkbox non cochée, abandon');
    return;
    }

    // Extraction et sanitisation des champs CORRIGÉS
    $email = isset($meta_data['email-1']) ? sanitize_email($meta_data['email-1']) : '';
    $prenom = isset($meta_data['name-1']) ? sanitize_text_field($meta_data['name-1']) : '';
    $nom = isset($meta_data['name-2']) ? sanitize_text_field($meta_data['name-2']) : '';

    if (!is_email($email)) {
    error_log('Brevo: Email invalide - ' . $email);
    return;
    }

    error_log('Brevo: Traitement - Email: ' . $email . ', Prénom: ' . $prenom . ', Nom: ' . $nom);

    // Prépare le payload pour l'API Brevo
    $payload = array(
    'email' => $email,
    'firstName' => $prenom,
    'lastName' => $nom,
    'listIds' => array((int)$list_id),
    'updateEnabled' => true, // Mettre à jour si le contact existe
    );

    // Appel API Brevo
    $response = wp_remote_post('https://api.brevo.com/v3/contacts', array(
    'method' => 'POST',
    'headers' => array(
    'api-key' => $api_key,
    'Content-Type' => 'application/json',
    ),
    'body' => wp_json_encode($payload),
    'timeout' => 15,
    ));

    // Traitement de la réponse
    if (is_wp_error($response)) {
    error_log('Brevo API Error: ' . $response->get_error_message());
    return;
    }

    $status_code = wp_remote_retrieve_response_code($response);
    $response_body = wp_remote_retrieve_body($response);

    if ($status_code >= 200 && $status_code < 300) {
    // Succès
    error_log('✅ Brevo: Contact ajouté/mis à jour - ' . $email);
    } else {
    // Erreur API
    error_log('❌ Brevo API Error (' . $status_code . '): ' . $response_body);
    }

    }, 10, 2);

    But i don’t understand nothing was sended to brevo and i didn’t have anything in wplog ….
    thanks for any help

    • This topic was modified 2 days, 11 hours ago by yberges.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hello @yberges

    Thanks for sharing us the code, but take note that custom PHP code is out of our support scope. While Forminator doesn’t include a direct integration to Brevo, it has integration to it by using webhooks:
    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#webhook

    You can use a service like Zapier, in order to send Forminator data to Brevo. Forminator supports any webhook service like Integrately, Tray.io, Make, Workato, n8n.io; and each one may have support for Brevo.

    Brevo, in the other hand, has integration with Google Sheet, although it also suggest the use of an integration tool, you can use Google Apps Scripts for a direct integration. In the case of Forminator, you can send the data to a Google Sheet directly so Brevo can use it to sync data to the platform:
    https://www.brevo.com/integrations/google-sheets/

    I suggest you to try the Forminator webhook or Google Sheet integration in order to connect to Brevo; and if you have issues with that, please let us know.

    Kind regards,
    Jair.

    Thread Starter yberges

    (@yberges)

    ok i will try

    Plugin Support Imran – WPMU DEV Support

    (@wpmudev-support9)

    Hi @yberges,

    Hope things are going well for you.

    Sure, please update us on the outcome. Alternatively, you can try the Hustle Popup plugin, which allows you to embed the Forminator form and integrate with Brevo. It has direct integration. You can refer to this guide: https://wpmudev.com/docs/wpmu-dev-plugins/hustle/#brevo.

    Please give it a try and share the results with us.


    Kind Regards,
    Imran Khan

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.