<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $to = "1stgengrl@gmail.com"; // Your email
    $subject = "New Contact Form Submission";

    // Sanitize form input
    $name = strip_tags(trim($_POST["name"]));
    $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
    $message = htmlspecialchars(trim($_POST["message"]));

    // Build email body
    $email_content = "Name: $name\n";
    $email_content .= "Email: $email\n\n";
    $email_content .= "Message:\n$message\n";

    // Use a fixed from email address on your domain
    $from_email = "rayagyekum88@gmail.com"; // Change this to your domain email or hosting default

    $headers = "From: 1st Gen Website <$from_email>\r\n";
    $headers .= "Reply-To: $name <$email>\r\n";
    $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

    // Send email
    if (mail($to, $subject, $email_content, $headers)) {
        echo "<p class='confirmation'>Thank you! We'll get back to you soon.</p>";
    } else {
        echo "<p class='confirmation' style='color: red;'>Something went wrong. Please try again.</p>";
    }
} else {
    // Block direct access
    header("Location: contact.html");
    exit;
}
