<?php
require_once 'config.php';
require_once 'helpers.php';
header('Content-Type: application/json; charset=utf-8');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(['success' => false, 'error' => 'Mthode non autorise']);
    exit;
}

$email = trim($_POST['email'] ?? '');
$consent = isset($_POST['consent']);

if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo json_encode(['success' => false, 'error' => 'Email invalide']);
    exit;
}

if (!$consent) {
    echo json_encode(['success' => false, 'error' => 'Consentement obligatoire']);
    exit;
}

try {
    // Vrifier si l