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

$response = [];

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name    = trim($_POST["form_name"] ?? '');
    $email   = trim($_POST["form_email"] ?? '');
    $subject = trim($_POST["form_subject"] ?? '');
    $phone   = trim($_POST["form_phone"] ?? '');
    $message = trim($_POST["form_message"] ?? '');

    if ($name && $email && $subject && $message) {
        $to = "mimasoftwaregroups@gmail.com"; // ← Replace with your email
        $email_subject = "Contact Form: $subject";
        $email_body = "Name: $name\nEmail: $email\nPhone: $phone\nMessage:\n$message";
        $headers = "From: $email";

        if (mail($to, $email_subject, $email_body, $headers)) {
            $response['status'] = 'true';
            $response['message'] = 'Thank you! Your message has been sent.';
        } else {
            $response['status'] = 'false';
            $response['message'] = 'Sorry, mail could not be sent.';
        }
    } else {
        $response['status'] = 'false';
        $response['message'] = 'Please fill in all required fields.';
    }
} else {
    $response['status'] = 'false';
    $response['message'] = 'Invalid request.';
}

echo json_encode($response);
