54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
ini_set('display_errors', 0);
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
|
|
|
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 (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
header("Location: index.php?status=error&msg=Invalid+email#contact");
|
|
exit;
|
|
}
|
|
|
|
if (empty($name) || empty($message)) {
|
|
header("Location: index.php?status=error&msg=Please+fill+out+all+fields#contact");
|
|
exit;
|
|
}
|
|
|
|
$to = getenv('MAIL_TO') ?: (getenv('MAIL_FROM') ?: 'admin@example.com');
|
|
$subject = "New Contact Form Submission from " . $name;
|
|
|
|
$html_content = "<h3>New Contact Form Submission</h3>";
|
|
$html_content .= "<p><b>Name:</b> " . htmlspecialchars($name) . "</p>";
|
|
$html_content .= "<p><b>Email:</b> " . htmlspecialchars($email) . "</p>";
|
|
$html_content .= "<p><b>Message:</b><br>" . nl2br(htmlspecialchars($message)) . "</p>";
|
|
|
|
$text_content = "New Contact Form Submission\n";
|
|
$text_content .= "Name: " . $name . "\n";
|
|
$text_content .= "Email: " . $email . "\n";
|
|
$text_content .= "Message:\n" . $message . "\n";
|
|
|
|
$options = [
|
|
'reply_to' => $email,
|
|
'from_name' => $name
|
|
];
|
|
|
|
$result = MailService::sendMail($to, $subject, $html_content, $text_content, $options);
|
|
|
|
if (!empty($result['success'])) {
|
|
header("Location: index.php?status=success#contact");
|
|
exit;
|
|
} else {
|
|
error_log("MailService Error: " . ($result['error'] ?? 'Unknown error'));
|
|
header("Location: index.php?status=error&msg=Could+not+send+message#contact");
|
|
exit;
|
|
}
|
|
} else {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|