116 lines
6.0 KiB
PHP
116 lines
6.0 KiB
PHP
<?php
|
|
$message_status = '';
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
require_once __DIR__ . '/mail/MailService.php';
|
|
|
|
$name = trim($_POST['name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$message = trim($_POST['message'] ?? '');
|
|
|
|
if (empty($name) || empty($email) || empty($message)) {
|
|
$error_message = 'Please fill out all fields.';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$error_message = 'Please enter a valid email address.';
|
|
} else {
|
|
$to = getenv('MAIL_TO') ?: 'admin@example.com'; // Fallback recipient
|
|
$subject = 'New Contact Form Message from ' . $name;
|
|
|
|
$res = MailService::sendContactMessage($name, $email, $message, $to, $subject);
|
|
|
|
if (!empty($res['success'])) {
|
|
$message_status = 'success';
|
|
} else {
|
|
$error_message = 'Sorry, there was an error sending your message. Please try again later.';
|
|
// Log the actual error: error_log("MailService Error: " . $res['error']);
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Contact Us - LAMP Demo</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body class="bg-light">
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">
|
|
<i class="bi bi-lightbulb-fill text-primary"></i>
|
|
LAMP Demo
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="vibe.php">Vibe</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="sandbox.php">Sandbox</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="seo.php">SEO</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="admin.php">Admin</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="contact.php">Contact</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="card shadow-sm">
|
|
<div class="card-body p-5">
|
|
<h1 class="display-5 text-center mb-4">Contact Us</h1>
|
|
<?php if ($message_status === 'success'): ?>
|
|
<div class="alert alert-success text-center">
|
|
<h4>Thank You!</h4>
|
|
<p>Your message has been sent successfully. We will get back to you shortly.</p>
|
|
<a href="index.php" class="btn btn-primary">Return Home</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger">- <?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
<p class="text-center text-muted mb-4">Have a question or feedback? Fill out the form below to get in touch with us.</p>
|
|
<form action="contact.php" method="POST">
|
|
<div class="form-floating mb-3">
|
|
<input type="text" class="form-control" id="name" name="name" placeholder="Your Name" required value="<?php echo htmlspecialchars($_POST['name'] ?? ''); ?>">
|
|
<label for="name">Your Name</label>
|
|
</div>
|
|
<div class="form-floating mb-3">
|
|
<input type="email" class="form-control" id="email" name="email" placeholder="Your Email" required value="<?php echo htmlspecialchars($_POST['email'] ?? ''); ?>">
|
|
<label for="email">Your Email</label>
|
|
</div>
|
|
<div class="form-floating mb-4">
|
|
<textarea class="form-control" id="message" name="message" placeholder="Your Message" required style="height: 150px;"><?php echo htmlspecialchars($_POST['message'] ?? ''); ?></textarea>
|
|
<label for="message">Your Message</label>
|
|
</div>
|
|
<div class="text-center">
|
|
<button type="submit" class="btn btn-primary btn-lg"><i class="bi bi-send-fill"></i> Send Message</button>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="alert alert-warning text-center mt-4">This is for testing purposes only — Flatlogic does not guarantee usage of the mail server. Please set up your own SMTP in <code>.env</code> (MAIL_/SMTP_ vars).</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="bg-white text-center text-muted py-4 mt-5 border-top">
|
|
<div class="container">
|
|
<p class="mb-0">© <?php echo date("Y"); ?> LAMP Demo. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|