36945-vm/contact.php
2025-12-14 19:20:06 +00:00

30 lines
1.0 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/mail/MailService.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = strip_tags(trim($_POST["name"]));
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = strip_tags(trim($_POST["message"]));
if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$_SESSION['error'] = "Please fill out all fields and provide a valid email address.";
header("Location: index.php#contact");
exit;
}
// The $to address should be configured in your .env file as MAIL_TO
$res = MailService::sendContactMessage($name, $email, $message);
if (!empty($res['success'])) {
$_SESSION['success'] = "Thank you for your message! I will get back to you shortly.";
} else {
$_SESSION['error'] = "Sorry, there was an error sending your message. Please try again later.";
error_log("MailService Error: " . ($res['error'] ?? 'Unknown error'));
}
header("Location: index.php#contact");
exit;
}
?>