46 lines
1.8 KiB
PHP
46 lines
1.8 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/mail/MailService.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = trim($_POST['name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$phone = trim($_POST['phone'] ?? '');
|
|
$message = trim($_POST['message'] ?? '');
|
|
|
|
if (empty($name) || empty($email) || empty($message)) {
|
|
$_SESSION['error_message'] = 'Please fill in all required fields.';
|
|
header('Location: help.php');
|
|
exit;
|
|
}
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$_SESSION['error_message'] = 'Invalid email format.';
|
|
header('Location: help.php');
|
|
exit;
|
|
}
|
|
|
|
$subject = 'New Help Request from ' . $name;
|
|
$html_content = "<p><strong>Name:</strong> {$name}</p>\n <p><strong>Email:</strong> {$email}</p>\n <p><strong>Phone:</strong> {$phone}</p>\n <p><strong>Message:</strong></p>\n <p>{$message}</p>";
|
|
$text_content = "Name: {$name}\nEmail: {$email}\nPhone: {$phone}\nMessage:\n{$message}";
|
|
|
|
// The recipient's email address. Using environment variable or a default.
|
|
$to = getenv('MAIL_TO') ?: 'support@majuroeats.com';
|
|
|
|
$result = MailService::sendMail($to, $subject, $html_content, $text_content, ['reply_to' => $email]);
|
|
|
|
if ($result['success']) {
|
|
$_SESSION['success_message'] = 'Thank you for your message! We will get back to you shortly.';
|
|
} else {
|
|
$_SESSION['error_message'] = 'Sorry, there was an error sending your message. Please try again later.';
|
|
// Optional: Log the error for debugging
|
|
// error_log('MailService Error: ' . $result['error']);
|
|
}
|
|
|
|
header('Location: help.php');
|
|
exit;
|
|
} else {
|
|
header('Location: help.php');
|
|
exit;
|
|
}
|