33991-vm/contact.php
Flatlogic Bot 6bbcab2491 wolf
2025-09-10 10:18:07 +00:00

96 lines
3.7 KiB
PHP

<?php
$successMessage = '';
$errorMessage = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Include the MailService
require_once __DIR__ . '/mail/MailService.php';
// Sanitize and validate inputs
$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 (empty($name) || !filter_var($email, FILTER_VALIDATE_EMAIL) || empty($message)) {
$errorMessage = 'Please fill out all fields correctly.';
} else {
// Use the MailService to send the email
// The 'to' address will be picked up from the .env configuration (MAIL_TO)
$result = MailService::sendContactMessage($name, $email, $message);
if (!empty($result['success'])) {
$successMessage = "Thank you for your message! We'll get back to you shortly.";
} else {
// Do not echo the raw error to the user for security.
// In a real app, you would log $result['error'].
$errorMessage = 'Sorry, there was an error sending your message. Please try again later.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Us - TrailGo</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<style>
body {
background-color: #F8F9FA;
}
.contact-form {
max-width: 600px;
margin: 50px auto;
padding: 30px;
background-color: #FFFFFF;
border-radius: .5rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}
</style>
</head>
<body>
<div class="container">
<div class="contact-form">
<h2 class="text-center mb-4">Contact Us</h2>
<?php if ($successMessage): ?>
<div class="alert alert-success" role="alert">
<?php echo $successMessage; ?>
</div>
<?php endif; ?>
<?php if ($errorMessage): ?>
<div class="alert alert-danger" role="alert">
<?php echo $errorMessage; ?>
</div>
<?php endif; ?>
<form action="contact.php" method="post">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
</form>
<div class="text-center mt-3">
<a href="/">Back to Home</a>
</div>
</div>
</div>
<!-- Bootstrap 5 JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>