<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $firstName = htmlspecialchars($_POST['fname']);
    $lastName = htmlspecialchars($_POST['lname']);
    $email = htmlspecialchars($_POST['cemail']);
    $phone = htmlspecialchars($_POST['cphone']);
    $message = htmlspecialchars($_POST['cmessage']);

    $to = "contactus@ayazalilawfirm.com";
    $cc = "ayazali@ayazalifirm.com"; // CC email
    $subject = "New Contact Form Submission";

    $body = "You have received a new message:\n\n";
    $body .= "First Name: $firstName\n";
    $body .= "Last Name: $lastName\n";
    $body .= "Email: $email\n";
    $body .= "Phone: $phone\n\n";
    $body .= "Message:\n$message\n";

    $headers = "From: $email\r\n";
    $headers .= "Reply-To: $email\r\n";
    $headers .= "CC: $cc\r\n"; // Add CC header

    if (mail($to, $subject, $body, $headers)) {
        http_response_code(200); // Success
        echo "Message sent successfully!";
    } else {
        http_response_code(500); // Server error
        echo "Failed to send message.";
    }
}
?>
