Demande de devis

Assuré principal




Conjoint





Nombre d’enfants à assurer







Coordonnées





ouinon

function handle_secure_contact_form() {
// Vérification des permissions
if (!isset($_POST[‘secure_contact_nonce’]) ||
!wp_verify_nonce($_POST[‘secure_contact_nonce’], ‘secure_contact_action’)) {
wp_die(‘Sécurité : nonce invalide’,  », array(‘response’ => 403));
}

// Honeypot — si rempli, suspect
if (!empty($_POST[‘contact_website’])) {
wp_die(‘Spam suspect détecté.’,  », array(‘response’ => 400));
}

// Validation et nettoyage des données
$name = sanitize_text_field( $_POST[‘contact_name’] );
$email = sanitize_email( $_POST[‘contact_email’] );
$message = sanitize_textarea_field( $_POST[‘contact_message’] );

if (empty($name) || empty($email) || !is_email($email) || empty($message)) {
wp_die(‘Formulaire invalide : veuillez vérifier les champs.’,  », array(‘response’ => 400));
}

// reCAPTCHA — vérification côté serveur
$recaptcha_response = sanitize_text_field($_POST[‘g-recaptcha-response’]);
$remote_ip = $_SERVER[‘REMOTE_ADDR’];
$secret_key = ‘VOTRE_SECRET_KEY’;

$response = wp_remote_post(‘https://www.google.com/recaptcha/api/siteverify’, array(
‘body’ => array(
‘secret’ => $secret_key,
‘response’ => $recaptcha_response,
‘remoteip’ => $remote_ip,
)
));

if ( is_wp_error($response) ) {
wp_die(‘Erreur de validation du CAPTCHA.’,  », array(‘response’ => 500));
}

$response_body = wp_remote_retrieve_body($response);
$result = json_decode($response_body);

if (!$result || !$result->success) {
wp_die(‘CAPTCHA non validé. Merci de réessayer.’,  », array(‘response’ => 400));
}

// Préparation de l’email
$to = get_option(‘admin_email’);
$subject = ‘[Contact] ‘ . $name;
$headers = array(
‘From: ‘ . get_bloginfo(‘name’) . ‘ <contact@’ . $_SERVER[‘SERVER_NAME’] . ‘>’,
‘Reply-To: ‘ . $email,
‘Content-Type: text/plain; charset=UTF-8’,
);
$body = « Nom : $name\n »;
$body .= « Email : $email\n\n »;
$body .= « Message :\n$message\n »;

// Envoi via SMTP (nécessite plugin comme WP Mail SMTP)
wp_mail($to, $subject, $body, $headers);

wp_redirect( home_url(‘/merci-contact’) );
exit;
}
// Point d’entrée pour admin-post
add_action(‘admin_post_nopriv_secure_contact’, ‘handle_secure_contact_form’);
add_action(‘admin_post_secure_contact’, ‘handle_secure_contact_form’);