<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $nombre   = htmlspecialchars($_POST["nombre"]);
    $email    = htmlspecialchars($_POST["email"]);
    $telefono = htmlspecialchars($_POST["telefono"] ?? '');
    $mensaje  = htmlspecialchars($_POST["mensaje"]);

    $to = "info@nucleologico.com.ar"; // tu correo destino
    $subject = "Nuevo mensaje desde nucleologico.com.ar";
    $body = "Nombre / Empresa: $nombre\nEmail: $email\nTeléfono: $telefono\n\nMensaje:\n$mensaje";
    $headers = "From: noreply@nucleologico.com.ar\r\nReply-To: $email";

    if (mail($to, $subject, $body, $headers)) {
        echo "<script>alert('Gracias, se ha enviado tu consulta.');window.location.href='/#contacto';</script>";
    } else {
        echo "<script>alert('Error al enviar el mensaje. Intenta nuevamente.');window.location.href='/#contacto';</script>";
    }
}
?>
