34838-vm/contact.php
Flatlogic Bot 1588e14fde 0.01
2025-10-09 16:28:10 +00:00

39 lines
1.5 KiB
PHP

<?php
header('Content-Type: application/json');
// This is a simplified example.
// In a real application, you would use the MailService.
// require_once __DIR__ . '/mail/MailService.php';
$response = ['success' => false, 'message' => 'An unknown error occurred.'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$message = trim($_POST['message'] ?? '');
if (empty($name) || empty($email) || empty($message)) {
$response['message'] = 'Please fill in all fields.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$response['message'] = 'Please provide a valid email address.';
} else {
// In a real scenario, you would call the mail service here.
// For now, we just simulate a success response.
// $mailResponse = MailService::sendContactMessage($name, $email, $message);
// if (!empty($mailResponse['success'])) {
// $response['success'] = true;
// $response['message'] = 'Thank you for your message! We will get back to you shortly.';
// } else {
// $response['message'] = 'Sorry, there was an error sending your message. Please try again later.';
// }
// Simulate success for this example
$response['success'] = true;
$response['message'] = 'Thank you for your message! We will get back to you shortly.';
}
} else {
$response['message'] = 'Invalid request method.';
}
echo json_encode($response);