36945-vm/contact.php
2025-12-18 17:27:42 +00:00

37 lines
1.3 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/mail/MailService.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Honeypot check
if (!empty($_POST['honeypot'])) {
// This is a bot, redirect with a success message
$_SESSION['success'] = "Thank you for your message! I will get back to you shortly.";
header("Location: index.php#contact");
exit;
}
$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;
}
$res = MailService::sendContactMessage($name, $email, $message, 'sgoodwin@northwoodmortgage.com');
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;
}
?>