message: email sending ready

This commit is contained in:
Dharmaraj Shrestha 2025-02-19 16:41:09 +05:45
parent 9f2c0fec1d
commit e827dc6ccb
13 changed files with 407 additions and 131 deletions

View File

@ -37,7 +37,7 @@
<h3>Request for Booking</h3>
<p>Fill your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items"></form>
<input type="hidden" name="car_name" value="beetle">
<div class="row">
<!-- Name Field -->

View File

@ -1,42 +1,4 @@
<?php include('header.php') ?>
<!-- Bootstrap CSS (Include if not already added) -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Toast Container (Fixed Position) -->
<div class="position-fixed top-0 end-0 p-3" style="z-index: 1050">
<?php if (isset($_GET['status'])): ?>
<div id="statusToast" class="toast align-items-center text-white bg-<?php echo ($_GET['status'] == 'success' ? 'success' : ($_GET['status'] == 'error' ? 'danger' : 'warning')); ?> border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<?php
if ($_GET['status'] == 'success') {
echo "✅ Message sent successfully!";
} elseif ($_GET['status'] == 'error') {
// echo "❌ There was an error sending your message. Please try again.";
echo "❌ There was an error: " . htmlspecialchars($_GET['message']);
} elseif ($_GET['status'] == 'missing_fields') {
echo "⚠️ Please fill in all required fields.";
}
?>
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
<?php $_GET['status'] = null; ?>
<?php endif; ?>
</div>
<!-- Bootstrap JS & Auto Hide Toast Script -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
let statusToast = document.getElementById("statusToast");
if (statusToast) {
let toast = new bootstrap.Toast(statusToast, { delay: 3000 }); // Auto-hide after 3s
toast.show();
}
});
</script>
<!--<< Breadcrumb Section Start >>-->
<div class="breadcrumb-wrapper bg-cover" style="background-image: url('img/bg-header-banner.jpg');">
@ -73,7 +35,7 @@
Drop us a Line
</h2>
</div>
<form action="mail.php" id="contact-form" method="POST" class="contact-form-items mt-5 mt-md-0">
<form action="mailContact.php" id="contact-form" method="POST" class="contact-form-items mt-5 mt-md-0">
<div class="row g-4">
<div class="col-lg-6">
<div class="form-clt">
@ -81,6 +43,7 @@
<input type="text" name="name" id="name" placeholder="Your Name">
</div>
</div>
<div class="col-lg-6">
<div class="form-clt">
<label for="">Email</label>

View File

@ -37,7 +37,7 @@
<h3>Request for Booking</h3>
<p>Fill your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Ford Ecosport">
<div class="row">
<!-- Name Field -->

View File

@ -1,3 +1,42 @@
<!-- Bootstrap CSS (Include if not already added) -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Toast Container (Fixed Position) -->
<div class="position-fixed top-0 end-0 p-3" style="z-index: 1050">
<?php if (isset($_GET['status'])): ?>
<div id="statusToast" class="toast align-items-center text-white bg-<?php echo ($_GET['status'] == 'success' ? 'success' : ($_GET['status'] == 'error' ? 'danger' : 'warning')); ?> border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<?php
if ($_GET['status'] == 'success') {
echo "✅ Message sent successfully!";
} elseif ($_GET['status'] == 'error') {
// echo "❌ There was an error sending your message. Please try again.";
echo "❌ There was an error: " . htmlspecialchars($_GET['message']);
} elseif ($_GET['status'] == 'missing_fields') {
echo "⚠️ Please fill in all required fields.";
}
?>
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
<?php $_GET['status'] = null; ?>
<?php endif; ?>
</div>
<!-- Bootstrap JS & Auto Hide Toast Script -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
let statusToast = document.getElementById("statusToast");
if (statusToast) {
let toast = new bootstrap.Toast(statusToast, { delay: 3000 }); // Auto-hide after 3s
toast.show();
}
});
</script>
<!DOCTYPE html>
<html lang="en">
<!--<< Header Area >>-->

View File

@ -37,7 +37,7 @@
<h3>Request for Booking</h3>
<p>Fill your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Honda City">
<div class="row">
<!-- Name Field -->

264
mailBooking.php Normal file
View File

@ -0,0 +1,264 @@
<?php include('mailCredentials.php'); ?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// A helper function to build the redirect URL with a status parameter
function buildRedirectUrl($status, $extra = '')
{
// If HTTP_REFERER isn't set, use a default page
$redirect = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'car-grid.php';
// Check if the URL already has query parameters
$separator = (strpos($redirect, '?') !== false) ? '&' : '?';
// Build and return the new URL
return $redirect . $separator . "status=" . $status . $extra;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get form data and sanitize inputs
$name = htmlspecialchars(trim($_POST['name']));
$car_name = htmlspecialchars(trim($_POST['car_name']));
$location = htmlspecialchars(trim($_POST['location']));
$pickup_date = htmlspecialchars(trim($_POST['pickup_date']));
$dropoff_date = htmlspecialchars(trim($_POST['dropoff_date']));
$user_email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
$phone = htmlspecialchars(trim($_POST['phone']));
$subject = $car_name . " Booking";
// Check if all required fields are provided
if (
!empty($name) && !empty($user_email)
&& !empty($location) && !empty($pickup_date) && !empty($dropoff_date) && !empty($phone)
) {
try {
/*** User Confirmation Email ***/
$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', $support_name);
$userMail->addAddress($user_email);
$userMail->isHTML(true);
$userMail->Subject = "Thank you for contacting ". $support_name;
// Embed logo
$userMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid');
// User Email Template (Responsive & clean design)
$userMail->Body = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Booking Confirmation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.email-container {
max-width: 600px;
margin: 0 auto;
font-family: Arial, sans-serif;
padding: 1rem;
}
.header {
text-align: center;
padding-bottom: 1rem;
}
.details {
background: #f8f9fa;
padding: 1.5rem;
border-radius: 8px;
margin: 1rem 0;
}
.footer {
text-align: center;
font-size: 0.8rem;
color: #666;
margin-top: 1rem;
}
</style>
</head>
<body>
<div class="email-container">
<div class="header">
<img src="cid:logo_cid" alt="Company Logo" style="max-height: 80px;">
<h2 class="mt-3">Booking Confirmation</h2>
</div>
<p>Dear {$name},</p>
<p>Thank you for reaching out to $support_name. We have received your booking request. Below are your booking details:</p>
<div class="details">
<h4>Booking Details</h4>
<p><strong>Car Name:</strong> {$car_name}</p>
<p><strong>Drop-off Location:</strong> {$location}</p>
<p><strong>Pickup Date:</strong> {$pickup_date}</p>
<p><strong>Drop-off Date:</strong> {$dropoff_date}</p>
</div>
<p>Our team will contact you shortly to confirm your booking and provide further details.</p>
<p>If you have any questions, please reply to this email.</p>
<p>Best regards,<br>$support_name Team</p>
<div class="footer">
<p>{$company_name} | {$company_address}</p>
<p>Email: {$company_email} | Phone: {$company_phone}</p>
</div>
<p class="mb-0"><em>If you didn't initiate this booking, please ignore this email. This may have been sent in error.</em></p>
</div>
</body>
</html>
HTML;
/*** Admin Notification Email ***/
$adminMail = new PHPMailer(true);
// SMTP Configuration
$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', $support_name);
$adminMail->addAddress($company_email);
$adminMail->addReplyTo($user_email, $name);
$adminMail->isHTML(true);
$adminMail->Subject = "New Booking Request: {$subject}";
// Embed logo for admin email
$adminMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid');
$currentDateTime = date('Y-m-d H:i:s');
// Admin Email Template (all details nicely presented)
$adminMail->Body = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>New Booking Request</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.email-container {
max-width: 800px;
margin: 0 auto;
font-family: Arial, sans-serif;
padding: 1rem;
}
.header {
text-align: center;
padding-bottom: 1rem;
}
.details {
background: #f8f9fa;
padding: 1.5rem;
border-radius: 8px;
margin: 1rem 0;
}
.details h4 {
margin-bottom: 1rem;
}
.details p {
margin: 0.5rem 0;
}
.footer {
text-align: center;
font-size: 0.8rem;
color: #666;
margin-top: 1rem;
}
.btn-reply {
margin-top: 1rem;
}
</style>
</head>
<body>
<div class="email-container">
<div class="header">
<img src="cid:logo_cid" alt="Company Logo" style="max-height: 80px;">
<h2 class="mt-3">New Booking Request Received</h2>
</div>
<div class="details">
<h4>Booking Information</h4>
<p><strong>Full Name:</strong> {$name}</p>
<p><strong>Email:</strong> {$user_email}</p>
<p><strong>Phone Number:</strong> {$phone}</p>
<p><strong>Car Name:</strong> {$car_name}</p>
<p><strong>Drop-off Location:</strong> {$location}</p>
<p><strong>Pickup Date:</strong> {$pickup_date}</p>
<p><strong>Drop-off Date:</strong> {$dropoff_date}</p>
<p><strong>Subject:</strong> {$subject}</p>
<p><strong>Message:</strong><br>{$message}</p>
</div>
<div class="text-center">
<a href="mailto:{$user_email}?subject=Re: {$subject}" class="btn btn-primary btn-reply">Reply to {$name}</a>
</div>
<div class="footer">
<p>{$company_name} | {$company_address}</p>
<p>Email: {$company_email} | Phone: {$company_phone}</p>
<p>Received on: {$currentDateTime}</p>
</div>
</div>
</body>
</html>
HTML;
// Send the emails
$userMail->send();
$adminMail->send();
// Redirect back to the referring page with a success status
$redirectUrl = buildRedirectUrl('success');
header("Location: $redirectUrl");
exit();
} catch (Exception $e) {
// On error, encode the message and redirect back with the error status
$errorMessage = "&message=" . urlencode($e->getMessage());
$redirectUrl = buildRedirectUrl('error', $errorMessage);
header("Location: $redirectUrl");
exit();
}
} else {
// Missing fields: redirect back with missing_fields status
$redirectUrl = buildRedirectUrl('missing_fields');
header("Location: $redirectUrl");
exit();
}
}
// Include header after potential redirects
include('header.php');
// Handle status messages (this part is optional if you want to display messages on the referring page)
if (isset($_GET['status'])) {
switch ($_GET['status']) {
case 'success':
echo "<p class='alert alert-success'>✅ Your message has been sent successfully!</p>";
break;
case 'error':
$error = isset($_GET['message']) ? htmlspecialchars($_GET['message']) : "There was an error sending your message. Please try again.";
echo "<p class='alert alert-danger'>❌ $error</p>";
break;
case 'missing_fields':
echo "<p class='alert alert-warning'>⚠️ Please fill in all the required fields.</p>";
break;
}
}
?>

View File

@ -1,13 +1,8 @@
<?php include('mailCredentials.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
@ -37,10 +32,10 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$userMail->Port = 587;
// User Email Configuration
$userMail->setFrom('noreply.nclex.email@gmail.com', 'NCLEX Support');
$userMail->setFrom('noreply.nclex.email@gmail.com', $support_name);
$userMail->addAddress($user_email);
$userMail->isHTML(true);
$userMail->Subject = "Thank you for contacting NCLEX Support";
$userMail->Subject = "Thank you for contacting " . $support_name;
// Embed logo
$userMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid');
@ -63,6 +58,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
<div class="card email-card">
<div class="card-body">
<div class="text-center mb-4">
<!-- Use the cid reference for the embedded image -->
<img src="cid:logo_cid" alt="Company Logo" class="company-logo">
</div>
<div class="text-center mb-4">
@ -105,7 +101,7 @@ HTML;
$adminMail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$adminMail->Port = 587;
$adminMail->setFrom('noreply.nclex.email@gmail.com', 'NCLEX Support');
$adminMail->setFrom('noreply.nclex.email@gmail.com', $support_name);
$adminMail->addAddress($company_email);
$adminMail->addReplyTo($user_email, $name);
$adminMail->isHTML(true);
@ -134,6 +130,7 @@ HTML;
<div class="card email-card">
<div class="card-body">
<div class="text-center mb-4">
<!-- Use the cid reference for the embedded image -->
<img src="cid:logo_cid" alt="Company Logo" class="company-logo">
</div>
<div class="alert alert-primary py-3">
@ -213,7 +210,6 @@ if (isset($_GET['status'])) {
case 'missing_fields':
header("Location: contact.php?status=missing_fields");
exit();
}
}
?>

7
mailCredentials.php Normal file
View File

@ -0,0 +1,7 @@
<?php
#you are required to change these credential only
$company_name= 'Bohara Rental Team';
$support_name= 'Bohara Rental Support';
$company_address = 'Kathmandu, Nepal';
$company_email = 'subedigokul119@gmail.com';
$company_phone = +9779800000000;

View File

@ -37,7 +37,7 @@
<h3>Request for Booking</h3>
<p>Fil your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Peugeot 308">
<div class="row">
<!-- Name Field -->

View File

@ -37,7 +37,7 @@
<h3>Request for Booking</h3>
<p>Fill your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Peugeot 308">
<div class="row">
<!-- Name Field -->

View File

@ -37,7 +37,7 @@
<h3>Request for Booking</h3>
<p>Fill your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Peugeot 308">
<div class="row">
<!-- Name Field -->

View File

@ -1,4 +1,4 @@
<?php
<!-- <?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
@ -96,4 +96,4 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
} else {
echo 'Invalid request method.';
}
?>
?> -->

View File

@ -1,5 +1,3 @@
<?php include('header.php') ?>
@ -23,7 +21,7 @@
<h1 class="wow fadeInUp" data-wow-delay=".5s">Peugeot</h1>
</div>
</div>
</div>
</div>
<!-- Car Details Section Start -->
<section class="car-details fix section-padding">
@ -37,14 +35,15 @@
<h3>Request for Booking</h3>
<p>Fill your requirement to us. We will check your request and contact you soon.</p>
</div>
<form action="" id="contact-form" method="POST" class="contact-form-items">
<form action="mailBooking.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Peugeot 308">
<div class="row">
<!-- Name Field -->
<div class="col-lg-6">
<div class="form-clt">
<label class="label-text">Your Name</label>
<input type="text" name="name" id="name" placeholder="Your Name" class="input-field" required>
<input type="text" name="name" id="name" placeholder="Your Name"
class="input-field" required>
</div>
</div>
@ -52,7 +51,8 @@
<div class="col-lg-6">
<div class="form-clt">
<label class="label-text">Email</label>
<input type="text" name="email" id="email" placeholder="example@gmail.com" class="input-field" >
<input type="text" name="email" id="email" placeholder="example@gmail.com"
class="input-field">
</div>
</div>
@ -60,14 +60,16 @@
<div class="col-lg-6">
<div class="form-clt">
<label class="label-text">Phone Number</label>
<input type="text" name="phone" id="phone" placeholder="+977 00 0000 - 000" class="input-field" required>
<input type="text" name="phone" id="phone" placeholder="+977 00 0000 - 000"
class="input-field" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-clt">
<label class="label-text">Drop-off Location</label>
<input type="text" name="location" id="location" placeholder="koteshor" class="input-field" required>
<input type="text" name="location" id="location" placeholder="koteshor"
class="input-field" required>
</div>
</div>
@ -75,8 +77,10 @@
<div class="form-clt">
<label class="label-text">Pick-up Date</label>
<div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy">
<input name='pickup_date' class="form-control" type="text" placeholder="Check in" readonly>
<span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span>
<input name='pickup_date' class="form-control" type="text"
placeholder="Check in" readonly>
<span class="input-group-addon"> <i
class="fa-solid fa-calendar-days"></i></span>
</div>
</div>
</div>
@ -84,8 +88,10 @@
<div class="form-clt">
<label class="label-text">Drop-off Date</label>
<div id="datepicker2" class="input-group date" data-date-format="dd-mm-yyyy">
<input class="form-control" type="text" name = 'dropoff_date' placeholder="Check in" readonly>
<span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span>
<input class="form-control" type="text" name='dropoff_date'
placeholder="Check in" readonly>
<span class="input-group-addon"> <i
class="fa-solid fa-calendar-days"></i></span>
</div>
</div>
</div>
@ -120,7 +126,8 @@
<h3>Peugeot 308</h3>
<h6>$70.00 <span>/ Day</span></h6>
<p class="mt-4 mb-4">
To deliver on the promise of technology and human We help our clients become sions of themselves.
To deliver on the promise of technology and human We help our clients become sions of
themselves.
</p>
</div>