File: //home/jibhires/brightsolutionsindia.com/contact.php
<?php
// Enable error reporting (remove in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$current_page = 'Contact';
$page_title = "Contact Us";
include 'header.php';
// Load configuration from outside public_html
require dirname(__DIR__) . '/config.php';
// Load PHPMailer
require __DIR__ . '/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$success = false;
$error = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
// Sanitize inputs
$name = isset($_POST['name']) ? trim(htmlspecialchars($_POST['name'])) : '';
$email = isset($_POST['email']) ? trim(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL)) : '';
$phone = isset($_POST['phone']) ? trim(htmlspecialchars($_POST['phone'])) : '';
$message = isset($_POST['message']) ? trim(htmlspecialchars($_POST['message'])) : '';
// Validate required fields
if (empty($name)) {
throw new Exception("Name is required");
}
if (empty($email)) {
throw new Exception("Email is required");
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new Exception("Invalid email format");
}
if (empty($message)) {
throw new Exception("Message is required");
}
// Create PHPMailer instance
$mail = new PHPMailer(true);
// Server settings
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USER;
$mail->Password = SMTP_PASS;
$mail->SMTPSecure = SMTP_SECURE;
$mail->Port = SMTP_PORT;
// Recipients
$mail->setFrom(FROM_EMAIL, FROM_NAME);
$mail->addAddress(RECIPIENT_EMAIL, RECIPIENT_NAME);
$mail->addReplyTo($email, $name);
// Content
$mail->isHTML(true);
$mail->Subject = 'New Inquiry from ' . $name;
$mail->Body = "
<h3>New Contact Form Submission</h3>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Phone:</strong> $phone</p>
<p><strong>Message:</strong><br>" . nl2br($message) . "</p>
";
$mail->send();
$success = true;
$_POST = []; // Clear form fields
} catch (Exception $e) {
$error = "Message could not be sent. Please try again later.";
error_log('Contact Form Error: ' . $e->getMessage());
}
}
?>
<section class="py-5">
<div class="container">
<div class="row g-5">
<div class="col-md-6">
<div class="bg-light p-4 rounded">
<h2 class="mb-4">Contact Information</h2>
<ul class="list-unstyled">
<li class="mb-3">
<i class="fas fa-user me-2"></i>
Sanjay Kumar
</li>
<li class="mb-3">
<i class="fas fa-phone me-2"></i>
+91 79883 34856
</li>
<li class="mb-3">
<i class="fas fa-envelope me-2"></i>
sales@brightsolutionsindia.com
</li>
</ul>
</div>
</div>
<div class="col-md-6">
<?php if ($success): ?>
<div class="alert alert-success">
<i class="fas fa-check-circle me-2"></i>
Thank you! Your message has been sent successfully.
</div>
<?php elseif (!empty($error)): ?>
<div class="alert alert-danger">
<i class="fas fa-exclamation-circle me-2"></i>
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form method="POST" class="shadow p-4 rounded">
<div class="mb-3">
<label class="form-label">Your Name *</label>
<input type="text" name="name" class="form-control" required
value="<?= isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '' ?>">
</div>
<div class="mb-3">
<label class="form-label">Email Address *</label>
<input type="email" name="email" class="form-control" required
value="<?= isset($_POST['email']) ? htmlspecialchars($_POST['email']) : '' ?>">
</div>
<div class="mb-3">
<label class="form-label">Contact Number</label>
<input type="tel" name="phone" class="form-control"
value="<?= isset($_POST['phone']) ? htmlspecialchars($_POST['phone']) : '' ?>">
</div>
<div class="mb-3">
<label class="form-label">Message *</label>
<textarea name="message" class="form-control" rows="5" required><?=
isset($_POST['message']) ? htmlspecialchars($_POST['message']) : ''
?></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-paper-plane me-2"></i>Send Message
</button>
</form>
</div>
</div>
</div>
</section>
<?php include 'footer.php'; ?>