/** * Formidable -> Brevo Double Opt-in * Form ID: 8 * Fields: Nombre 70 | Apellidos 71 | Email 72 * Brevo: List 14 | DOI Template 20 * Redirect: https://cesevilla.es/suscripcion-confirmada/ */ add_action('frm_after_create_entry', 'ces_send_brevo_doi_from_formidable', 10, 2); function ces_send_brevo_doi_from_formidable($entry_id, $form_id) { $FORM_ID = 8; if ((int) $form_id !== (int) $FORM_ID) { return; } // 🔐 Pega aquí tu API KEY de Brevo (v3) $api_key = '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'; // IDs de campos Formidable $FIELD_NOMBRE_ID = 70; $FIELD_APELLIDOS_ID = 71; $FIELD_EMAIL_ID = 72; // Datos Brevo $LIST_ID_BREVO = 14; // sin # $TEMPLATE_ID_DOI = 20; $REDIRECTION_URL = 'https://cesevilla.es/suscripcion-confirmada/'; // Obtener valores del envío $email = trim((string) frm_get_entry_meta($entry_id, $FIELD_EMAIL_ID, true)); $nombre = trim((string) frm_get_entry_meta($entry_id, $FIELD_NOMBRE_ID, true)); $apellidos = trim((string) frm_get_entry_meta($entry_id, $FIELD_APELLIDOS_ID, true)); if (!is_email($email)) { return; } $payload = array( 'email' => $email, 'includeListIds' => array((int) $LIST_ID_BREVO), 'redirectionUrl' => $REDIRECTION_URL, 'templateId' => (int) $TEMPLATE_ID_DOI, 'attributes' => array( 'NOMBRE' => $nombre, 'APELLIDOS' => $apellidos ) ); $response = wp_remote_post('https://api.brevo.com/v3/contacts/doubleOptinConfirmation', array( 'timeout' => 15, 'headers' => array( 'api-key' => $api_key, 'Content-Type' => 'application/json', 'Accept' => 'application/json' ), 'body' => wp_json_encode($payload) )); if (is_wp_error($response)) { error_log('Brevo DOI error: ' . $response->get_error_message()); return; } $code = (int) wp_remote_retrieve_response_code($response); // 201 = OK (solicitud DOI creada) if ($code !== 201) { $body = wp_remote_retrieve_body($response); error_log('Brevo DOI non-201: ' . $code . ' body=' . $body); } }