35804-vm/contact.php
2025-11-17 18:36:39 +00:00

29 lines
977 B
PHP

<?php
require_once __DIR__ . '/mail/MailService.php';
$name = $_POST['name'] ?? 'Anonymous';
$school = $_POST['school'] ?? 'Not provided';
$email = $_POST['email'] ?? '';
$message = $_POST['message'] ?? '';
if (empty($email) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
header('Location: index.php?status=error');
exit;
}
$body = "New contact form submission:\n\nName: {$name}\nSchool: {$school}\nEmail: {$email}\n\nMessage:\n{$message}";
// The MAIL_TO environment variable should be set to the desired recipient.
// If not set, it will fall back to MAIL_FROM.
$res = MailService::sendMail(null, 'New Contact Form Submission', nl2br($body), $body, ['reply_to' => $email]);
if (!empty($res['success'])) {
header('Location: index.php?status=success#contact');
} else {
// In a real app, you would log the error.
// error_log('MailService Error: ' . $res['error']);
header('Location: index.php?status=error#contact');
}
exit;