<?php

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

    $name    = htmlspecialchars($_POST['fname']);
    $email   = htmlspecialchars($_POST['email']);
    $phone   = htmlspecialchars($_POST['phone']);
    $message = htmlspecialchars($_POST['message']);

    $to = "ravi@onqanet.com"; // Your receiving email
    $subject = "New Contact Form Enquiry";

    $body = "
    Name: $name

    Email: $email

    Phone: $phone

    Message:
    $message
    ";

    $headers  = "From: $email\r\n";
    $headers .= "Reply-To: $email\r\n";
    $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

    if (mail($to, $subject, $body, $headers)) {
        echo "<script>
                alert('Message sent successfully.');
                window.location='contact.html';
              </script>";
    } else {
        echo "<script>
                alert('Failed to send message.');
                window.history.back();
              </script>";
    }
}
?>