true, 'message' => 'Mensaje recibido (spam bloqueado)']); exit; } // Validar campos requeridos $required_fields = ['nombre', 'email', 'division', 'mensaje']; foreach ($required_fields as $field) { if (empty($_POST[$field])) { echo json_encode(['success' => false, 'message' => 'Por favor, completá todos los campos obligatorios.']); exit; } } // Validar formato de email if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { echo json_encode(['success' => false, 'message' => 'El email ingresado no es válido.']); exit; } // Validar reCAPTCHA if (empty($_POST['g-recaptcha-response'])) { echo json_encode(['success' => false, 'message' => 'Por favor, completa el reCAPTCHA.']); exit; } // Verificar reCAPTCHA con Google $recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify'; $recaptcha_data = [ 'secret' => $RECAPTCHA_SECRET_KEY, 'response' => $_POST['g-recaptcha-response'], 'remoteip' => $_SERVER['REMOTE_ADDR'] ]; $recaptcha_options = [ 'http' => [ 'method' => 'POST', 'content' => http_build_query($recaptcha_data) ] ]; $recaptcha_context = stream_context_create($recaptcha_options); $recaptcha_result = file_get_contents($recaptcha_url, false, $recaptcha_context); $recaptcha_json = json_decode($recaptcha_result, true); if (!$recaptcha_json['success']) { echo json_encode(['success' => false, 'message' => 'Error de verificación reCAPTCHA. Por favor, intentá de nuevo.']); exit; } // ============================================ // PREPARAR Y ENVIAR EL EMAIL // ============================================ // Sanitizar datos $nombre = htmlspecialchars(strip_tags($_POST['nombre'])); $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); $empresa = isset($_POST['empresa']) ? htmlspecialchars(strip_tags($_POST['empresa'])) : 'No especificada'; $telefono = isset($_POST['telefono']) ? htmlspecialchars(strip_tags($_POST['telefono'])) : 'No especificado'; $division = htmlspecialchars(strip_tags($_POST['division'])); $tipo = isset($_POST['tipo']) && !empty($_POST['tipo']) ? htmlspecialchars(strip_tags($_POST['tipo'])) : 'No especificado'; $mensaje = htmlspecialchars(strip_tags($_POST['mensaje'])); $referencia = isset($_POST['referencia']) && !empty($_POST['referencia']) ? htmlspecialchars(strip_tags($_POST['referencia'])) : 'No especificado'; // Construir el cuerpo del email $email_subject = "Nuevo contacto desde VettaIO - $nombre"; $email_body = "
VettaIO - Transformamos desafíos tecnológicos