<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $full_name = trim($_POST["full_name"] ?? "");
    $company_name = trim($_POST["company_name"] ?? "");
    $email = trim($_POST["email"] ?? "");
    $phone = trim($_POST["phone"] ?? "");
    $service = trim($_POST["service"] ?? "");
    $message = trim($_POST["message"] ?? "");

    if ($full_name === "" || $email === "" || $phone === "" || $service === "" || $message === "") {
        header("Location: contact.html?status=error");
        exit;
    }

    $to = "info@rokn-altaqa.com";
    $subject = "New Inquiry";

    $body = "Full Name: " . $full_name . "\n";
    $body .= "Company Name: " . $company_name . "\n";
    $body .= "Email: " . $email . "\n";
    $body .= "Phone: " . $phone . "\n";
    $body .= "Required Service: " . $service . "\n\n";
    $body .= "Project Message:\n" . $message . "\n";

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

    if (mail($to, $subject, $body, $headers)) {
        header("Location: contact.html?status=success");
        exit;
    } else {
        header("Location: contact.html?status=error");
        exit;
    }
} else {
    header("Location: contact.html");
    exit;
}
?>