<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = htmlspecialchars(trim($_POST['name']));
    $email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
    $message = htmlspecialchars(trim($_POST['message']));

    if (!empty($name) && !empty($email) && !empty($message) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $to = "bruno@rbdrinks.fr";  // Replace with your email address
        $subject = "New Quote Request";
        $email_content = "Name: $name\n";
        $email_content .= "Email: $email\n";
        $email_content .= "Message:\n$message\n";

        $headers = "From: $name <$email>";

        if (mail($to, $subject, $email_content, $headers)) {
            echo '<script>alert("Thank you for your message!"); window.location.href="index.php";</script>';
        } else {
            echo '<script>alert("Oops! Something went wrong and we couldn\'t send your message."); window.location.href="index.php";</script>';
        }
    } else {
        echo '<script>alert("Please fill in all fields correctly."); window.location.href="index.php";</script>';
    }
} else {
    echo '<script>alert("There was a problem with your submission, please try again."); window.location.href="index.php";</script>';
}
?>