<?php
session_start();

require 'PHPMailer/PHPMailer/PHPMailerAutoload.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST['name'];
    $mobile = $_POST['mobile'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    // Validate input data (additional server-side validation can be added)

    if (empty($name) || empty($mobile) || empty($email) || empty($subject) || empty($message)) {
        echo "All fields are required.";
        exit();
    }

    // Configure PHPMailer
    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuth = true;
    $mail->Username = 'preetimahijpr@gmail.com'; // Replace with your Gmail address
    $mail->Password = 'Kanha@290919'; // Replace with your Gmail password

    $mail->setFrom($email, $name); // Replace with your Gmail address and your name
    $mail->addAddress('preetimahijpr@gmail.com', 'Pratibha'); // Replace with the recipient's email address and name

    $mail->Subject = 'New Contact Form Submission: ' . $subject;
    $mail->Body = "Name: $name\n\nMobile: $mobile\n\nEmail: $email\n\nMessage: $message";
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->Debugoutput = 'html'; // Display debug output as HTML
    // Send email
    if ($mail->send()) {
        $_SESSION['msg'] = 'ok';
        header('location: index.php');
        exit();
    } else {
        $_SESSION['msg'] = 'fail';
        header('location: index.php');
        exit();
    }
}
?>
