<?php
header('Content-Type: application/json');

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $firstname = $_POST['firstname'] ?? '';
    $lastname = $_POST['lastname'] ?? '';
    $email = $_POST['email'] ?? '';
    $budget = $_POST['budget'] ?? '';
    $service = $_POST['service_required'] ?? '';
    $message = $_POST['message'] ?? '';

    $to = "farzee.diginar@gmail.com"; // Replace with your real email
    $subject = "New Contact Form Submission";
    $body = "First Name: $firstname\n";
    $body .= "Last Name: $lastname\n";
    $body .= "Email: $email\n";
    $body .= "Budget: $budget\n";
    $body .= "Service Required: $service\n";
    $body .= "Message: $message\n";
    $headers = "From: $email\r\nReply-To: $email\r\n";

    if (mail($to, $subject, $body, $headers)) {
        http_response_code(200);
        echo json_encode(["success" => true, "message" => "Email sent"]);
    } else {
        http_response_code(500);
        echo json_encode(["success" => false, "error" => "mail() failed"]);
    }
} else {
    http_response_code(405);
    echo json_encode(["success" => false, "error" => "Invalid request method"]);
}
?>
