27 lines
981 B
PHP
27 lines
981 B
PHP
<?php
|
|
require_once __DIR__ . '/mail/MailService.php';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$name = filter_var(trim($_POST["name"]), FILTER_SANITIZE_STRING);
|
|
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
|
|
$message = filter_var(trim($_POST["message"]), FILTER_SANITIZE_STRING);
|
|
|
|
if (empty($name) || !filter_var($email, FILTER_VALIDATE_EMAIL) || empty($message)) {
|
|
header("Location: index.php?status=error");
|
|
exit;
|
|
}
|
|
|
|
// The MailService will use the default recipient from the .env file
|
|
// It will use the sender's email as the Reply-To address.
|
|
$res = MailService::sendContactMessage($name, $email, $message);
|
|
|
|
if (!empty($res['success'])) {
|
|
header("Location: index.php?status=success#contact");
|
|
} else {
|
|
// In a real app, you would log the error stored in $res['error']
|
|
header("Location: index.php?status=error#contact");
|
|
}
|
|
} else {
|
|
header("Location: index.php");
|
|
}
|