<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $name    = trim($_POST['your_name']);
    $email   = trim($_POST['your_email']);
    $phone   = trim($_POST['your_phone']);
    $subject = trim($_POST['your_subject']);
    $message = trim($_POST['your_message']);

    // Validate
    if (!$name || !$email || !$phone || !$subject || !$message) {
        echo "All fields are required.";
        exit;
    }

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo "Invalid email address.";
        exit;
    }

    // Email destination
    $to = "info@texascapitalbg.com";

    $email_subject = "Contact Form: " . $subject;

    $body = "
Name: $name
Email: $email
Phone: $phone
Subject: $subject

Message:
$message
";

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

    if (mail($to, $email_subject, $body, $headers)) {
        echo "Message sent successfully!";
    } else {
        echo "Failed to send message.";
    }

} else {
    echo "Invalid request.";
}
?>