<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Data capture karna
    $name = htmlspecialchars($_POST['full_name']);
    $email = htmlspecialchars($_POST['email']);
    $phone = htmlspecialchars($_POST['phone']);
    $subject = htmlspecialchars($_POST['subject']);
    $message = htmlspecialchars($_POST['message']);
    $date = date("Y-m-d H:i:s");

    // 1. CSV File mein save karna (Database ki zaroorat nahi)
    $file = 'leads.csv';
    $data = [$date, $name, $email, $phone, $subject, $message];
    
    $fp = fopen($file, 'a');
    fputcsv($fp, $data);
    fclose($fp);

    // 2. Email Notification (Optional: Apna email yahan daalein)
    $to = "support@mytravelbudy.com"; 
    $email_subject = "New Lead: $subject - $name";
    $email_body = "You have received a new inquiry.\n\n".
                  "Name: $name\n".
                  "Email: $email\n".
                  "Phone: $phone\n".
                  "Subject: $subject\n".
                  "Message: $message";
    
    mail($to, $email_subject, $email_body);

    // 3. Success Message display karna
    echo "<!DOCTYPE html>
    <html>
    <head>
        <script src='https://cdn.tailwindcss.com'></script>
    </head>
    <body class='bg-slate-50 flex items-center justify-center h-screen'>
        <div class='text-center p-10 bg-white shadow-2xl rounded-3xl border border-orange-500'>
            <h1 class='text-3xl font-black text-blue-900 mb-4 uppercase'>Message Sent!</h1>
            <p class='text-gray-600 mb-6'>Thank you, $name. We will contact you within 60 minutes.</p>
            <a href='index.html' class='bg-orange-600 text-white px-8 py-3 rounded-full font-bold uppercase text-sm'>Go Back Home</a>
        </div>
    </body>
    </html>";
} else {
    header("Location: contact.html");
}
?>