<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>


<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $month = $_POST['month'];
    $duration = $_POST['duration'];
    $type = $_POST['type'];

    $mail = new PHPMailer(true);

    try {
        $mail->isSMTP();
        $mail->Host       = 'smtp.gmail.com'; // Change if using hosting email
        $mail->SMTPAuth   = true;
        $mail->Username   = 'avipramedia@gmail.com'; // YOUR EMAIL
        $mail->Password   = 'elmv ykrz qxcm rbqk';   // Gmail App Password
        $mail->SMTPSecure = 'tls';
        $mail->Port       = 587;

        $mail->setFrom('info@souvenirtravelindia.com', 'Website Lead');
        $mail->addAddress('sales.souvenirtravel2021@gmail.com');

        $mail->Subject = 'New Rajasthan Tour Lead';
        $mail->Body    = "
        New Inquiry Received:

        Name: $name
        Email: $email
        Phone: $phone
        Travel Month: $month
        Duration: $duration
        Tour Style: $type
        ";

        $mail->send();
        echo "<script>alert('Thank you! We will contact you soon.'); window.location.href='thankyou.html';</script>";

    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
}
?>
