39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
require_once 'db/config.php';
|
|
|
|
$name = trim($_POST['name']);
|
|
$email = trim($_POST['email']);
|
|
$message = trim($_POST['message']);
|
|
|
|
if (empty($name) || empty($email) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$_SESSION['error'] = "Please fill out all fields with valid information.";
|
|
header("Location: /#contact");
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$sql = "INSERT INTO contact_submissions (name, email, message) VALUES (?, ?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$name, $email, $message]);
|
|
|
|
$_SESSION['success'] = "Thank you for your message. We will get back to you shortly.";
|
|
|
|
// Optionally send an email notification
|
|
// require_once 'mail/MailService.php';
|
|
// MailService::sendContactMessage($name, $email, $message);
|
|
|
|
} catch (PDOException $e) {
|
|
// In a real app, you would log this error
|
|
$_SESSION['error'] = "Sorry, there was an error submitting your message. Please try again later.";
|
|
}
|
|
|
|
header("Location: /#contact");
|
|
exit();
|
|
} else {
|
|
header("Location: /");
|
|
exit();
|
|
} |