<?php
include 'db.php'; // يحتوي على $conn

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $email = $_POST['email'];

    $stmt = $conn->prepare("INSERT INTO newsletter (email) VALUES (?)");

    try {
        $stmt->execute([$email]);
        // الاشتراك ناجح
        header("Location: index.php?subscribe=success");
        exit;
    } catch (Exception $e) {
        // البريد مسجل مسبقاً
        header("Location: index.php?subscribe=exists");
        exit;
    }
}
?>
