<?php
// Get form values
$helpType = $_POST['help_type'] ?? '';
$name = $_POST['name'] ?? '';
$phone = $_POST['phone'] ?? '';

// Validate required fields
if (empty($helpType) || empty($name) || empty($phone)) {
    echo "<script>
        alert('Please fill in all required fields.');
        window.history.back();
    </script>";
    exit;
}

// Set your email
$to = "developerm4b@gmail.com, info@settlemitra.com"; // Replace with your email

// Email subject and body
$subject = "Quick Help Request: $helpType";
$body = "
Help Type: $helpType
Name: $name
Phone: $phone
";

$headers = "From: $name <no-reply@yourdomain.com>\r\n"; // Replace with your domain
$headers .= "Reply-To: no-reply@yourdomain.com\r\n";

// Send email
$sent = mail($to, $subject, $body, $headers);

// Output response
if ($sent) {
    echo "<script>
        alert('Thank you! We will contact you shortly.');
        window.location.href = 'index.php';
    </script>";
} else {
    echo "<script>
        alert('Something went wrong. Please try again.');
        window.history.back();
    </script>";
}
?>
