36789-vm/contact.php
Flatlogic Bot 19f1cf94a2 v0.1
2025-12-09 14:54:28 +00:00

34 lines
1.0 KiB
PHP

<?php
require_once __DIR__ . '/mail/MailService.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$message = trim($_POST['message'] ?? '');
if (empty($name) || !filter_var($email, FILTER_VALIDATE_EMAIL) || empty($message)) {
// Basic validation failed
header('Location: index.php?status=error#appointment-form');
exit;
}
// Send email
$subject = 'New Appointment Request';
$res = MailService::sendContactMessage($name, $email, $message, null, $subject);
if (!empty($res['success'])) {
header('Location: index.php?status=success#appointment-form');
exit;
} else {
// Log error if possible, then redirect
error_log('MailService Error: ' . ($res['error'] ?? 'Unknown error'));
header('Location: index.php?status=error#appointment-form');
exit;
}
} else {
// If not a POST request, redirect to home
header('Location: index.php');
exit;
}