94 lines
4.5 KiB
PHP
94 lines
4.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/mail/MailService.php';
|
|
$page_title = 'Request a Service';
|
|
$message = '';
|
|
$message_type = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = trim($_POST['name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$service_message = trim($_POST['message'] ?? '');
|
|
|
|
if (empty($name) || empty($email) || empty($service_message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$message = 'Please fill in all fields correctly.';
|
|
$message_type = 'red';
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare(
|
|
'INSERT INTO service_requests (name, email, message) VALUES (?, ?, ?)'
|
|
);
|
|
$stmt->execute([$name, $email, $service_message]);
|
|
|
|
// Notify Admin
|
|
$admin_email = getenv('MAIL_TO') ?: 'admin@example.com';
|
|
$subject = 'New Service Request from ' . $name;
|
|
$html_content = "
|
|
<h1>New Service Request</h1>
|
|
<p><strong>Name:</strong> {$name}</p>
|
|
<p><strong>Email:</strong> {$email}</p>
|
|
<p><strong>Message:</strong></p>
|
|
<p>{$service_message}</p>
|
|
<p>This request is now pending approval in the admin dashboard.</p>
|
|
";
|
|
$text_content = strip_tags($html_content);
|
|
|
|
MailService::sendMail($admin_email, $subject, $html_content, $text_content);
|
|
|
|
$message = 'Thank you! Your service request has been submitted successfully. An account manager will review it shortly.';
|
|
$message_type = 'green';
|
|
} catch (PDOException $e) {
|
|
// In a real app, log this error.
|
|
$message = 'Sorry, there was an error submitting your request. Please try again later.';
|
|
$message_type = 'red';
|
|
} catch (Exception $e) {
|
|
$message = 'Sorry, there was an error sending the notification. Please try again later.';
|
|
$message_type = 'red';
|
|
}
|
|
}
|
|
}
|
|
|
|
require_once __DIR__ . '/header.php';
|
|
?>
|
|
|
|
<div class="max-w-4xl mx-auto">
|
|
<div class="bg-white rounded-lg shadow-md">
|
|
<div class="p-8">
|
|
<h1 class="text-3xl font-bold text-center text-gray-800 mb-6"><?php echo $page_title; ?></h1>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="p-4 mb-6 text-sm text-<?php echo $message_type; ?>-700 bg-<?php echo $message_type; ?>-100 rounded-lg" role="alert">
|
|
<?php echo htmlspecialchars($message); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($message_type !== 'green'): ?>
|
|
<form action="request-service.php" method="POST" class="space-y-6">
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-gray-700">Full Name</label>
|
|
<div class="mt-1">
|
|
<input type="text" name="name" id="name" required class="w-full px-3 py-2 placeholder-gray-400 border border-gray-300 rounded-md shadow-sm appearance-none focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label for="email" class="block text-sm font-medium text-gray-700">Email Address</label>
|
|
<div class="mt-1">
|
|
<input type="email" name="email" id="email" required class="w-full px-3 py-2 placeholder-gray-400 border border-gray-300 rounded-md shadow-sm appearance-none focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label for="message" class="block text-sm font-medium text-gray-700">Describe the service you need</label>
|
|
<div class="mt-1">
|
|
<textarea id="message" name="message" rows="5" required class="w-full px-3 py-2 placeholder-gray-400 border border-gray-300 rounded-md shadow-sm appearance-none focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="text-center">
|
|
<button type="submit" class="inline-block px-8 py-3 text-lg font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Submit Request</button>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/footer.php'; ?>
|