<?php
// Get form inputs
$name = $_POST['name'] ?? '';
$callno = $_POST['callno'] ?? '';
$email = $_POST['email'] ?? '';
$loan = $_POST['loan'] ?? '';
$message = $_POST['message'] ?? '';

// Basic validation
if (empty($name) || empty($callno) || empty($email) || empty($loan)) {
    echo "<script>
        alert('Please fill in all required fields.');
        window.history.back();
    </script>";
    exit;
}

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

// Subject and content
$subject = "Loan Settlement Form Submission from $name";
$body = "
Name: $name
Phone: $callno
Email: $email
Loan Type: $loan

Message:
$message
";

$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $email\r\n";

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

if ($sent) {
    echo "<script>
        alert('Thank you! Your request has been submitted.');
        window.location.href = 'index.php';
    </script>";
} else {
    echo "<script>
        alert('There was an error sending your request. Please try again.');
        window.history.back();
    </script>";
}
?>
