34 lines
1.0 KiB
PHP
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;
|
|
}
|