219 lines
9.3 KiB
PHP
219 lines
9.3 KiB
PHP
|
<?php
|
||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||
|
use PHPMailer\PHPMailer\Exception;
|
||
|
|
||
|
#you are required to change these credential only
|
||
|
$company_name= 'Nclex Team';
|
||
|
$company_address = 'Kathmandu, Nepal';
|
||
|
$company_email = 'subedigokul119@gmail.com';
|
||
|
$company_phone = +9779800000000;
|
||
|
|
||
|
require 'vendor/autoload.php';
|
||
|
|
||
|
// Enable error reporting
|
||
|
error_reporting(E_ALL);
|
||
|
ini_set('display_errors', 1);
|
||
|
|
||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||
|
// Get form data
|
||
|
$name = htmlspecialchars(trim($_POST['name']));
|
||
|
$user_email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
|
||
|
$phone = htmlspecialchars(trim($_POST['phone']));
|
||
|
$subject = htmlspecialchars(trim($_POST['subject']));
|
||
|
$message = htmlspecialchars(trim($_POST['message']));
|
||
|
|
||
|
if (!empty($name) && !empty($user_email) && !empty($phone) && !empty($subject) && !empty($message)) {
|
||
|
try {
|
||
|
// Send confirmation email to user
|
||
|
$userMail = new PHPMailer(true);
|
||
|
|
||
|
// SMTP Configuration
|
||
|
$userMail->isSMTP();
|
||
|
$userMail->Host = 'smtp.gmail.com';
|
||
|
$userMail->SMTPAuth = true;
|
||
|
$userMail->Username = 'noreply.nclex.email@gmail.com';
|
||
|
$userMail->Password = 'gmbe nypd ofcl vpmi';
|
||
|
$userMail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||
|
$userMail->Port = 587;
|
||
|
|
||
|
// User Email Configuration
|
||
|
$userMail->setFrom('noreply.nclex.email@gmail.com', 'NCLEX Support');
|
||
|
$userMail->addAddress($user_email);
|
||
|
$userMail->isHTML(true);
|
||
|
$userMail->Subject = "Thank you for contacting NCLEX Support";
|
||
|
|
||
|
// Embed logo
|
||
|
$userMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid');
|
||
|
|
||
|
// User Email Template
|
||
|
$userMail->Body = <<<HTML
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||
|
<style>
|
||
|
.email-card { max-width: 800px; margin: 2rem auto; border-radius: 15px; }
|
||
|
.company-logo { height: 60px; margin-bottom: 1rem; }
|
||
|
.disclaimer { font-size: 0.8rem; color: #666; }
|
||
|
.highlight-box { background: #f8f9fa; border-radius: 10px; padding: 1.5rem; margin: 1rem 0; }
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="container">
|
||
|
<div class="card email-card">
|
||
|
<div class="card-body">
|
||
|
<div class="text-center mb-4">
|
||
|
<img src="cid:logo_cid" alt="Company Logo" class="company-logo">
|
||
|
</div>
|
||
|
<div class="text-center mb-4">
|
||
|
<div class="text-success">
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="currentColor" class="bi bi-check2-circle" viewBox="0 0 16 16">
|
||
|
<path d="M2.5 8a5.5 5.5 0 0 1 8.25-4.764.5.5 0 0 0 .5-.866A6.5 6.5 0 1 0 14.5 8a.5.5 0 0 0-1 0 5.5 5.5 0 1 1-11 0z"/>
|
||
|
<path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z"/>
|
||
|
</svg>
|
||
|
</div>
|
||
|
<h2 class="mt-3">Message Received!</h2>
|
||
|
</div>
|
||
|
<div class="highlight-box">
|
||
|
<p class="lead">Thank you for contacting us, $name!</p>
|
||
|
<p>We've successfully received your message and our team will get back to you within 24-48 hours.</p>
|
||
|
<p class="text-muted"><small>Your email address ($user_email) is safe with us. We never share your information with third parties.</small></p>
|
||
|
</div>
|
||
|
<footer class="mt-4 text-center">
|
||
|
<div class="disclaimer">
|
||
|
<p class="mb-1"><strong> $company_name; </strong></p>
|
||
|
<p class="mb-1">$company_address; </p>
|
||
|
<p class="mb-1">Email: $company_email; | Phone: $company_phone; </p>
|
||
|
<hr>
|
||
|
<p class="mb-0"><em>If you didn't initiate this contact, please ignore this email. This may have been sent in error.</em></p>
|
||
|
</div>
|
||
|
</footer>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|
||
|
HTML;
|
||
|
|
||
|
// Send admin email
|
||
|
$adminMail = new PHPMailer(true);
|
||
|
$adminMail->isSMTP();
|
||
|
$adminMail->Host = 'smtp.gmail.com';
|
||
|
$adminMail->SMTPAuth = true;
|
||
|
$adminMail->Username = 'noreply.nclex.email@gmail.com';
|
||
|
$adminMail->Password = 'gmbe nypd ofcl vpmi';
|
||
|
$adminMail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||
|
$adminMail->Port = 587;
|
||
|
|
||
|
$adminMail->setFrom('noreply.nclex.email@gmail.com', 'NCLEX Support');
|
||
|
$adminMail->addAddress($company_email);
|
||
|
$adminMail->addReplyTo($user_email, $name);
|
||
|
$adminMail->isHTML(true);
|
||
|
$adminMail->Subject = "New Contact: $subject";
|
||
|
|
||
|
// Embed logo for admin email
|
||
|
$adminMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid');
|
||
|
|
||
|
// Admin Email Template
|
||
|
$currentDateTime = date('Y-m-d H:i:s');
|
||
|
$adminMail->Body = <<<HTML
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||
|
<style>
|
||
|
.email-card { max-width: 800px; margin: 2rem auto; border-radius: 15px; box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); }
|
||
|
.company-logo { height: 80px; margin-bottom: 1.5rem; }
|
||
|
.detail-badge { background: #f8f9fa; border-radius: 8px; padding: 1rem; margin: 0.5rem; flex: 1 1 45%; }
|
||
|
.reply-btn { padding: 12px 30px; border-radius: 8px; transition: all 0.3s ease; }
|
||
|
.highlight-box { background: linear-gradient(145deg, #f8f9fa, #ffffff); border-radius: 12px; padding: 2rem; margin: 1.5rem 0; box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); }
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="container">
|
||
|
<div class="card email-card">
|
||
|
<div class="card-body">
|
||
|
<div class="text-center mb-4">
|
||
|
<img src="cid:logo_cid" alt="Company Logo" class="company-logo">
|
||
|
</div>
|
||
|
<div class="alert alert-primary py-3">
|
||
|
<h2 class="alert-heading fs-4 mb-3">📬 New Contact Form Submission</h2>
|
||
|
<p class="mb-0">Action required: Please respond to the user inquiry</p>
|
||
|
</div>
|
||
|
<div class="text-center mb-4">
|
||
|
<a href="mailto:$user_email?subject=Re: $subject" class="btn btn-primary reply-btn">✉️ Reply to $name</a>
|
||
|
</div>
|
||
|
<div class="highlight-box">
|
||
|
<div class="row g-3">
|
||
|
<div class="col-12"><h4 class="mb-3">👤 User Details</h4></div>
|
||
|
<div class="col-md-6"><div class="detail-badge"><span class="text-muted small">Full Name</span><div class="fw-bold text-dark">$name</div></div></div>
|
||
|
<div class="col-md-6"><div class="detail-badge"><span class="text-muted small">Email Address</span><div class="fw-bold text-primary">$user_email</div></div></div>
|
||
|
<div class="col-md-6"><div class="detail-badge"><span class="text-muted small">Phone Number</span><div class="fw-bold text-dark">$phone</div></div></div>
|
||
|
<div class="col-md-6"><div class="detail-badge"><span class="text-muted small">Subject</span><div class="fw-bold text-info">$subject</div></div></div>
|
||
|
<div class="col-12"><div class="detail-badge"><span class="text-muted small">Message</span><div class="fw-bold text-dark mt-2">$message</div></div></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<footer class="mt-4 text-center">
|
||
|
<div class="disclaimer">
|
||
|
<div class="row g-2">
|
||
|
<div class="col-12">
|
||
|
<p class="mb-1"><strong>🏢 $company_name;</strong></p>
|
||
|
<p class="mb-1">📍 $company_address; </p>
|
||
|
<p class="mb-1">📧 $company_email; | 📞 $company_phone; </p>
|
||
|
</div>
|
||
|
<div class="col-12">
|
||
|
<hr>
|
||
|
<p class="small text-muted mb-0">⚠️ Automated message - Received at: $currentDateTime</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</footer>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|
||
|
HTML;
|
||
|
|
||
|
// Send emails
|
||
|
$userMail->send();
|
||
|
$adminMail->send();
|
||
|
|
||
|
// Redirect to prevent resubmission
|
||
|
header("Location: contact.php?status=success");
|
||
|
exit();
|
||
|
|
||
|
} catch (Exception $e) {
|
||
|
$errorMessage = urlencode($e->getMessage()); // Encode for safe URL usage
|
||
|
header("Location: contact.php?status=error&message=$errorMessage");
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
header("Location: contact.php?status=missing_fields");
|
||
|
exit();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Include header after potential redirects
|
||
|
include('header.php');
|
||
|
|
||
|
// Handle status messages
|
||
|
if (isset($_GET['status'])) {
|
||
|
switch ($_GET['status']) {
|
||
|
case 'success':
|
||
|
// After successful email sending
|
||
|
header("Location: contact.php?status=success");
|
||
|
exit();
|
||
|
|
||
|
case 'error':
|
||
|
header("Location: contact.php?status=error");
|
||
|
exit();
|
||
|
|
||
|
case 'missing_fields':
|
||
|
header("Location: contact.php?status=missing_fields");
|
||
|
exit();
|
||
|
|
||
|
}
|
||
|
}
|
||
|
?>
|