send email

This commit is contained in:
subashGamer21 2025-01-13 13:51:48 +05:45
parent 60cd431f83
commit 9fad4f5106
14 changed files with 7878 additions and 62 deletions

View File

@ -124,7 +124,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
gap: 190px; gap: 190px;
transform: translateX(95px); /* Moves the element 20px to the right */ transform: translateX(75px); /* Moves the element 20px to the right */
} }
@media (max-width: 900px) { @media (max-width: 900px) {
.search-text, .search-text,
@ -132,3 +132,39 @@
display: none; display: none;
} }
} }
@media (max-width: 768px) {
.logo {
position: absolute; /* Or fixed if you want it to stay while scrolling */
right: 1px; /* Position it on the right side */
z-index: 10; /* Ensure it's on top of other content */
}
.header-logo img {
width: auto; /* Ensure the logo does not get stretched */
height: 30px; /* Adjust logo size if needed */
}
}
.popup-message {
display: none; /* Initially hidden */
position: fixed;
top: 20%;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
color: white;
padding: 20px;
border-radius: 5px;
font-size: 16px;
z-index: 9999;
}
.popup-message.error {
background-color: #f44336; /* Red background for error messages */
}
.popup-message .close-btn {
margin-left: 20px;
cursor: pointer;
font-weight: bold;
}

View File

@ -170,7 +170,7 @@
</div> </div>
</div> </div>
</footer> </footer>
<!-- <script src="js/custom.js"></script> -->
<!--<< All JS Plugins >>--> <!--<< All JS Plugins >>-->
<script src="js/jquery-3.7.1.min.js"></script> <script src="js/jquery-3.7.1.min.js"></script>
<!--<< Viewport Js >>--> <!--<< Viewport Js >>-->

9
js/custom.js Normal file
View File

@ -0,0 +1,9 @@
document.getElementById("contact-form").addEventListener("submit", function(event) {
event.preventDefault(); // Prevents form from submitting immediately
// Display the alert message
if (confirm("Booking has been confirmed!")) {
// If OK is pressed, redirect to another page
window.location.href = "car-grid.php";
}
});

View File

@ -2,6 +2,7 @@
<?php include('header.php') ?> <?php include('header.php') ?>
<!--<< Breadcrumb Section Start >>--> <!--<< Breadcrumb Section Start >>-->
<div class="breadcrumb-wrapper bg-cover" style="background-image: url('img/bg-header-banner.jpg');"> <div class="breadcrumb-wrapper bg-cover" style="background-image: url('img/bg-header-banner.jpg');">
<div class="container"> <div class="container">
@ -23,6 +24,7 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Car Details Section Start --> <!-- Car Details Section Start -->
<section class="car-details fix section-padding"> <section class="car-details fix section-padding">
<div class="container"> <div class="container">
@ -31,7 +33,7 @@
<div class="col-lg-8"> <div class="col-lg-8">
<div class="car-details-items"> <div class="car-details-items">
<div class="car-image"> <div class="car-image">
<img src="img/Cars/navara.jpg" alt="img"> <img src="img/Cars/peugeot_308.jpg" alt="img">
</div> </div>
<div class="car-content"> <div class="car-content">
<div class="star"> <div class="star">
@ -42,7 +44,7 @@
<i class="fa-solid fa-star"></i> <i class="fa-solid fa-star"></i>
<span>2 Reviews</span> <span>2 Reviews</span>
</div> </div>
<h3>navara</h3> <h3>Peugeot 308</h3>
<h6>$70.00 <span>/ Day</span></h6> <h6>$70.00 <span>/ Day</span></h6>
<p class="mt-4 mb-4"> <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.
@ -132,7 +134,8 @@
<h3>Request for Booking</h3> <h3>Request for Booking</h3>
<p>Send your requirement to us. We will check email and contact you soon.</p> <p>Send your requirement to us. We will check email and contact you soon.</p>
</div> </div>
<form action="#" id="contact-form" method="POST" class="contact-form-items"> <form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Peugeot 308">
<div class="row g-4"> <div class="row g-4">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="form-clt"> <div class="form-clt">
@ -198,7 +201,7 @@
<div class="form-clt"> <div class="form-clt">
<label class="label-text">Pick-up Date</label> <label class="label-text">Pick-up Date</label>
<div id="datepicker3" class="input-group date" data-date-format="dd-mm-yyyy"> <div id="datepicker3" class="input-group date" data-date-format="dd-mm-yyyy">
<input class="form-control" type="text" placeholder="Check in" readonly> <input class="form-control" name='pickup_date' type="text" placeholder="Check in" readonly>
<span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span> <span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span>
</div> </div>
</div> </div>
@ -207,33 +210,12 @@
<div class="form-clt"> <div class="form-clt">
<label class="label-text">Drop-off Date</label> <label class="label-text">Drop-off Date</label>
<div id="datepicker4" class="input-group date" data-date-format="dd-mm-yyyy"> <div id="datepicker4" class="input-group date" data-date-format="dd-mm-yyyy">
<input class="form-control" type="text" placeholder="Check in" readonly> <input class="form-control" name= 'dropoff_date' type="text" placeholder="Check in" readonly>
<span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span> <span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span>
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-5">
<div class="input-save-items-area">
<div class="input-save-items">
<div class="input-save d-flex align-items-center mb-3">
<input type="checkbox" class="form-check-input" name="save-for-next" id="saveForNext1">
<label for="saveForNext1">Driver</label>
</div>
<div class="input-save d-flex align-items-center">
<input type="checkbox" class="form-check-input" name="save-for-next" id="saveForNext2">
<label for="saveForNext2">Baby Seat</label>
</div>
</div>
<div class="input-save-items">
<div class="input-save d-flex align-items-center mb-3">
<label>$10.00 / Day</label>
</div>
<div class="input-save d-flex align-items-center">
<label>$30.00 / Total</label>
</div>
</div>
</div>
</div>
<div class="col-lg-12"> <div class="col-lg-12">
<button class="theme-btn" type="submit"> <button class="theme-btn" type="submit">
Send Request Send Request
@ -297,7 +279,8 @@
<div class="col-lg-4"> <div class="col-lg-4">
<div class="car-list-sidebar"> <div class="car-list-sidebar">
<h4 class="title">Other Car</h4> <h4 class="title">Other Car</h4>
<!-- Example content -->
<!-- Example Car Items -->
<div class="car-item"> <div class="car-item">
<a href="hondacity.php"> <a href="hondacity.php">
<img src="img/Cars/honda city.jpg" alt="Honda City"> <img src="img/Cars/honda city.jpg" alt="Honda City">
@ -324,10 +307,10 @@
</div> </div>
<div class="rate">1500/day</div> <div class="rate">1500/day</div>
</a> </a>
<a href="peugeot.php"> <a href="navara.php">
<img src="img/Cars/peugeot_308.jpg" alt="Honda City"> <img src="img/Cars/navara.jpg" alt="Honda City">
<div class="details"> <div class="details">
Peageot Navara
</div> </div>
<div class="rate">1000/day</div> <div class="rate">1000/day</div>
</a> </a>
@ -352,7 +335,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -44,7 +44,7 @@
</div> </div>
<div class="col-xl-4 col-lg-6"> <div class="col-xl-4 col-lg-6">
<div class="product-search-area"> <div class="product-search-area">
<form action="#" id="contact-form" method="POST"> <form action="car-grid.php" id="contact-form" method="POST">
<div class="row g-4"> <div class="row g-4">
<div class="col-md-12"> <div class="col-md-12">
<div class="pickup-items"> <div class="pickup-items">
@ -113,7 +113,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="pickup-items"> <div class="pickup-items">
<button type="submit" class="theme-btn"> <button type="submit" class="theme-btn">
Find a Car Rent a Car
</button> </button>
</div> </div>
</div> </div>

View File

@ -2,6 +2,7 @@
<?php include('header.php') ?> <?php include('header.php') ?>
<!--<< Breadcrumb Section Start >>--> <!--<< Breadcrumb Section Start >>-->
<div class="breadcrumb-wrapper bg-cover" style="background-image: url('img/bg-header-banner.jpg');"> <div class="breadcrumb-wrapper bg-cover" style="background-image: url('img/bg-header-banner.jpg');">
<div class="container"> <div class="container">
@ -23,6 +24,7 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Car Details Section Start --> <!-- Car Details Section Start -->
<section class="car-details fix section-padding"> <section class="car-details fix section-padding">
<div class="container"> <div class="container">
@ -132,7 +134,8 @@
<h3>Request for Booking</h3> <h3>Request for Booking</h3>
<p>Send your requirement to us. We will check email and contact you soon.</p> <p>Send your requirement to us. We will check email and contact you soon.</p>
</div> </div>
<form action="#" id="contact-form" method="POST" class="contact-form-items"> <form action="sendemail.php" id="contact-form" method="POST" class="contact-form-items">
<input type="hidden" name="car_name" value="Peugeot 308">
<div class="row g-4"> <div class="row g-4">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="form-clt"> <div class="form-clt">
@ -198,7 +201,7 @@
<div class="form-clt"> <div class="form-clt">
<label class="label-text">Pick-up Date</label> <label class="label-text">Pick-up Date</label>
<div id="datepicker3" class="input-group date" data-date-format="dd-mm-yyyy"> <div id="datepicker3" class="input-group date" data-date-format="dd-mm-yyyy">
<input class="form-control" type="text" placeholder="Check in" readonly> <input class="form-control" name='pickup_date' type="text" placeholder="Check in" readonly>
<span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span> <span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span>
</div> </div>
</div> </div>
@ -207,33 +210,12 @@
<div class="form-clt"> <div class="form-clt">
<label class="label-text">Drop-off Date</label> <label class="label-text">Drop-off Date</label>
<div id="datepicker4" class="input-group date" data-date-format="dd-mm-yyyy"> <div id="datepicker4" class="input-group date" data-date-format="dd-mm-yyyy">
<input class="form-control" type="text" placeholder="Check in" readonly> <input class="form-control" name= 'dropoff_date' type="text" placeholder="Check in" readonly>
<span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span> <span class="input-group-addon"> <i class="fa-solid fa-calendar-days"></i></span>
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-5">
<div class="input-save-items-area">
<div class="input-save-items">
<div class="input-save d-flex align-items-center mb-3">
<input type="checkbox" class="form-check-input" name="save-for-next" id="saveForNext1">
<label for="saveForNext1">Driver</label>
</div>
<div class="input-save d-flex align-items-center">
<input type="checkbox" class="form-check-input" name="save-for-next" id="saveForNext2">
<label for="saveForNext2">Baby Seat</label>
</div>
</div>
<div class="input-save-items">
<div class="input-save d-flex align-items-center mb-3">
<label>$10.00 / Day</label>
</div>
<div class="input-save d-flex align-items-center">
<label>$30.00 / Total</label>
</div>
</div>
</div>
</div>
<div class="col-lg-12"> <div class="col-lg-12">
<button class="theme-btn" type="submit"> <button class="theme-btn" type="submit">
Send Request Send Request

113
sendemail.php Normal file
View File

@ -0,0 +1,113 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Start session to store messages
session_start();
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect form data
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$phone = htmlspecialchars($_POST['phone']);
$address = htmlspecialchars($_POST['address']);
$location = htmlspecialchars($_POST['location']);
$pickup_date = htmlspecialchars($_POST['pickup_date']);
$dropoff_date = htmlspecialchars($_POST['dropoff_date']);
$car_name = htmlspecialchars($_POST['car_name']);
// Gmail credentials
$gmailUser = 'subashgiri939@gmail.com'; // Replace with your Gmail address
$gmailPassword = 'bwso nqdm rlri dpmj'; // Replace with your Gmail app password
// Create a new PHPMailer instance
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $gmailUser;
$mail->Password = $gmailPassword;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
// Send email to the customer
$mail->setFrom($gmailUser, 'Bohora Rental');
$mail->addAddress($email, $name); // Send to the customer's email address
$mail->isHTML(true);
$mail->Subject = 'Booking Confirmation';
$mail->Body = "
<h3>Your booking request has been received:</h3>
<p><strong>Name:</strong> $name</p>
<p><strong>Car Name:</strong> $car_name</p> <!-- Car Name Added -->
<p><strong>Phone:</strong> $phone</p>
<p><strong>Address:</strong> $address</p>
<p><strong>Pick-up Location:</strong> $location</p>
<p><strong>Pick-up Date:</strong> $pickup_date</p>
<p><strong>Drop-off Date:</strong> $dropoff_date</p>
<p>Thank you for your booking! We will contact you shortly for further details.</p>
";
$mail->AltBody = "
Your booking request has been received:
Name: $name
Phone: $phone
Address: $address
Pick-up Location: $location
Pick-up Date: $pickup_date
Drop-off Date: $dropoff_date
Thank you for your booking! We will contact you shortly for further details.
";
$mail->send();
// Send email to your Gmail (admin's email)
$mail->clearAddresses(); // Clear the previous recipient (customer)
$mail->addAddress($gmailUser, 'Your Company'); // Send to your company email
$mail->Subject = 'New Booking Request';
$mail->Body = "
<h3>You have received a new booking request:</h3>
<p><strong>Name:</strong> $name</p>
<p><strong>Car Name:</strong> $car_name</p> <!-- Car Name Added -->
<p><strong>Email:</strong> $email</p>
<p><strong>Phone:</strong> $phone</p>
<p><strong>Address:</strong> $address</p>
<p><strong>Pick-up Location:</strong> $location</p>
<p><strong>Pick-up Date:</strong> $pickup_date</p>
<p><strong>Drop-off Date:</strong> $dropoff_date</p>
<p>Please review the details for further action.</p>
";
$mail->AltBody = "
You have received a new booking request:
Name: $name
Email: $email
Phone: $phone
Address: $address
Pick-up Location: $location
Pick-up Date: $pickup_date
Drop-off Date: $dropoff_date
Car name : $car_name
Please review the details for further action.
";
$mail->send();
header('Location: car-grid.php'); // Redirect back to the form page after submission
exit();
} catch (Exception $e) {
header('Location: car-grid.php'); // Redirect back to the form page
exit();
}
} else {
echo 'Invalid request method.';
}
?>

245
src/DSNConfigurator.php Normal file
View File

@ -0,0 +1,245 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2023 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* Configure PHPMailer with DSN string.
*
* @see https://en.wikipedia.org/wiki/Data_source_name
*
* @author Oleg Voronkovich <oleg-voronkovich@yandex.ru>
*/
class DSNConfigurator
{
/**
* Create new PHPMailer instance configured by DSN.
*
* @param string $dsn DSN
* @param bool $exceptions Should we throw external exceptions?
*
* @return PHPMailer
*/
public static function mailer($dsn, $exceptions = null)
{
static $configurator = null;
if (null === $configurator) {
$configurator = new DSNConfigurator();
}
return $configurator->configure(new PHPMailer($exceptions), $dsn);
}
/**
* Configure PHPMailer instance with DSN string.
*
* @param PHPMailer $mailer PHPMailer instance
* @param string $dsn DSN
*
* @return PHPMailer
*/
public function configure(PHPMailer $mailer, $dsn)
{
$config = $this->parseDSN($dsn);
$this->applyConfig($mailer, $config);
return $mailer;
}
/**
* Parse DSN string.
*
* @param string $dsn DSN
*
* @throws Exception If DSN is malformed
*
* @return array Configuration
*/
private function parseDSN($dsn)
{
$config = $this->parseUrl($dsn);
if (false === $config || !isset($config['scheme']) || !isset($config['host'])) {
throw new Exception('Malformed DSN');
}
if (isset($config['query'])) {
parse_str($config['query'], $config['query']);
}
return $config;
}
/**
* Apply configuration to mailer.
*
* @param PHPMailer $mailer PHPMailer instance
* @param array $config Configuration
*
* @throws Exception If scheme is invalid
*/
private function applyConfig(PHPMailer $mailer, $config)
{
switch ($config['scheme']) {
case 'mail':
$mailer->isMail();
break;
case 'sendmail':
$mailer->isSendmail();
break;
case 'qmail':
$mailer->isQmail();
break;
case 'smtp':
case 'smtps':
$mailer->isSMTP();
$this->configureSMTP($mailer, $config);
break;
default:
throw new Exception(
sprintf(
'Invalid scheme: "%s". Allowed values: "mail", "sendmail", "qmail", "smtp", "smtps".',
$config['scheme']
)
);
}
if (isset($config['query'])) {
$this->configureOptions($mailer, $config['query']);
}
}
/**
* Configure SMTP.
*
* @param PHPMailer $mailer PHPMailer instance
* @param array $config Configuration
*/
private function configureSMTP($mailer, $config)
{
$isSMTPS = 'smtps' === $config['scheme'];
if ($isSMTPS) {
$mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
}
$mailer->Host = $config['host'];
if (isset($config['port'])) {
$mailer->Port = $config['port'];
} elseif ($isSMTPS) {
$mailer->Port = SMTP::DEFAULT_SECURE_PORT;
}
$mailer->SMTPAuth = isset($config['user']) || isset($config['pass']);
if (isset($config['user'])) {
$mailer->Username = $config['user'];
}
if (isset($config['pass'])) {
$mailer->Password = $config['pass'];
}
}
/**
* Configure options.
*
* @param PHPMailer $mailer PHPMailer instance
* @param array $options Options
*
* @throws Exception If option is unknown
*/
private function configureOptions(PHPMailer $mailer, $options)
{
$allowedOptions = get_object_vars($mailer);
unset($allowedOptions['Mailer']);
unset($allowedOptions['SMTPAuth']);
unset($allowedOptions['Username']);
unset($allowedOptions['Password']);
unset($allowedOptions['Hostname']);
unset($allowedOptions['Port']);
unset($allowedOptions['ErrorInfo']);
$allowedOptions = \array_keys($allowedOptions);
foreach ($options as $key => $value) {
if (!in_array($key, $allowedOptions)) {
throw new Exception(
sprintf(
'Unknown option: "%s". Allowed values: "%s"',
$key,
implode('", "', $allowedOptions)
)
);
}
switch ($key) {
case 'AllowEmpty':
case 'SMTPAutoTLS':
case 'SMTPKeepAlive':
case 'SingleTo':
case 'UseSendmailOptions':
case 'do_verp':
case 'DKIM_copyHeaderFields':
$mailer->$key = (bool) $value;
break;
case 'Priority':
case 'SMTPDebug':
case 'WordWrap':
$mailer->$key = (int) $value;
break;
default:
$mailer->$key = $value;
break;
}
}
}
/**
* Parse a URL.
* Wrapper for the built-in parse_url function to work around a bug in PHP 5.5.
*
* @param string $url URL
*
* @return array|false
*/
protected function parseUrl($url)
{
if (\PHP_VERSION_ID >= 50600 || false === strpos($url, '?')) {
return parse_url($url);
}
$chunks = explode('?', $url);
if (is_array($chunks)) {
$result = parse_url($chunks[0]);
if (is_array($result)) {
$result['query'] = $chunks[1];
}
return $result;
}
return false;
}
}

40
src/Exception.php Normal file
View File

@ -0,0 +1,40 @@
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output.
*
* @return string
*/
public function errorMessage()
{
return '<strong>' . htmlspecialchars($this->getMessage(), ENT_COMPAT | ENT_HTML401) . "</strong><br />\n";
}
}

139
src/OAuth.php Normal file
View File

@ -0,0 +1,139 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
use League\OAuth2\Client\Grant\RefreshToken;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Token\AccessToken;
/**
* OAuth - OAuth2 authentication wrapper class.
* Uses the oauth2-client package from the League of Extraordinary Packages.
*
* @see https://oauth2-client.thephpleague.com
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
*/
class OAuth implements OAuthTokenProvider
{
/**
* An instance of the League OAuth Client Provider.
*
* @var AbstractProvider
*/
protected $provider;
/**
* The current OAuth access token.
*
* @var AccessToken
*/
protected $oauthToken;
/**
* The user's email address, usually used as the login ID
* and also the from address when sending email.
*
* @var string
*/
protected $oauthUserEmail = '';
/**
* The client secret, generated in the app definition of the service you're connecting to.
*
* @var string
*/
protected $oauthClientSecret = '';
/**
* The client ID, generated in the app definition of the service you're connecting to.
*
* @var string
*/
protected $oauthClientId = '';
/**
* The refresh token, used to obtain new AccessTokens.
*
* @var string
*/
protected $oauthRefreshToken = '';
/**
* OAuth constructor.
*
* @param array $options Associative array containing
* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
*/
public function __construct($options)
{
$this->provider = $options['provider'];
$this->oauthUserEmail = $options['userName'];
$this->oauthClientSecret = $options['clientSecret'];
$this->oauthClientId = $options['clientId'];
$this->oauthRefreshToken = $options['refreshToken'];
}
/**
* Get a new RefreshToken.
*
* @return RefreshToken
*/
protected function getGrant()
{
return new RefreshToken();
}
/**
* Get a new AccessToken.
*
* @return AccessToken
*/
protected function getToken()
{
return $this->provider->getAccessToken(
$this->getGrant(),
['refresh_token' => $this->oauthRefreshToken]
);
}
/**
* Generate a base64-encoded OAuth token.
*
* @return string
*/
public function getOauth64()
{
//Get a new token if it's not available or has expired
if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {
$this->oauthToken = $this->getToken();
}
return base64_encode(
'user=' .
$this->oauthUserEmail .
"\001auth=Bearer " .
$this->oauthToken .
"\001\001"
);
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* OAuthTokenProvider - OAuth2 token provider interface.
* Provides base64 encoded OAuth2 auth strings for SMTP authentication.
*
* @see OAuth
* @see SMTP::authenticate()
*
* @author Peter Scopes (pdscopes)
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
*/
interface OAuthTokenProvider
{
/**
* Generate a base64-encoded OAuth token ensuring that the access token has not expired.
* The string to be base 64 encoded should be in the form:
* "user=<user_email_address>\001auth=Bearer <access_token>\001\001"
*
* @return string
*/
public function getOauth64();
}

5248
src/PHPMailer.php Normal file

File diff suppressed because it is too large Load Diff

469
src/POP3.php Normal file
View File

@ -0,0 +1,469 @@
<?php
/**
* PHPMailer POP-Before-SMTP Authentication Class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer POP-Before-SMTP Authentication Class.
* Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication.
* 1) This class does not support APOP authentication.
* 2) Opening and closing lots of POP3 connections can be quite slow. If you need
* to send a batch of emails then just perform the authentication once at the start,
* and then loop through your mail sending script. Providing this process doesn't
* take longer than the verification period lasts on your POP3 server, you should be fine.
* 3) This is really ancient technology; you should only need to use it to talk to very old systems.
* 4) This POP3 class is deliberately lightweight and incomplete, implementing just
* enough to do authentication.
* If you want a more complete class there are other POP3 classes for PHP available.
*
* @author Richard Davey (original author) <rich@corephp.co.uk>
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
*/
class POP3
{
/**
* The POP3 PHPMailer Version number.
*
* @var string
*/
const VERSION = '6.9.3';
/**
* Default POP3 port number.
*
* @var int
*/
const DEFAULT_PORT = 110;
/**
* Default timeout in seconds.
*
* @var int
*/
const DEFAULT_TIMEOUT = 30;
/**
* POP3 class debug output mode.
* Debug output level.
* Options:
* @see POP3::DEBUG_OFF: No output
* @see POP3::DEBUG_SERVER: Server messages, connection/server errors
* @see POP3::DEBUG_CLIENT: Client and Server messages, connection/server errors
*
* @var int
*/
public $do_debug = self::DEBUG_OFF;
/**
* POP3 mail server hostname.
*
* @var string
*/
public $host;
/**
* POP3 port number.
*
* @var int
*/
public $port;
/**
* POP3 Timeout Value in seconds.
*
* @var int
*/
public $tval;
/**
* POP3 username.
*
* @var string
*/
public $username;
/**
* POP3 password.
*
* @var string
*/
public $password;
/**
* Resource handle for the POP3 connection socket.
*
* @var resource
*/
protected $pop_conn;
/**
* Are we connected?
*
* @var bool
*/
protected $connected = false;
/**
* Error container.
*
* @var array
*/
protected $errors = [];
/**
* Line break constant.
*/
const LE = "\r\n";
/**
* Debug level for no output.
*
* @var int
*/
const DEBUG_OFF = 0;
/**
* Debug level to show server -> client messages
* also shows clients connection errors or errors from server
*
* @var int
*/
const DEBUG_SERVER = 1;
/**
* Debug level to show client -> server and server -> client messages.
*
* @var int
*/
const DEBUG_CLIENT = 2;
/**
* Simple static wrapper for all-in-one POP before SMTP.
*
* @param string $host The hostname to connect to
* @param int|bool $port The port number to connect to
* @param int|bool $timeout The timeout value
* @param string $username
* @param string $password
* @param int $debug_level
*
* @return bool
*/
public static function popBeforeSmtp(
$host,
$port = false,
$timeout = false,
$username = '',
$password = '',
$debug_level = 0
) {
$pop = new self();
return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
}
/**
* Authenticate with a POP3 server.
* A connect, login, disconnect sequence
* appropriate for POP-before SMTP authorisation.
*
* @param string $host The hostname to connect to
* @param int|bool $port The port number to connect to
* @param int|bool $timeout The timeout value
* @param string $username
* @param string $password
* @param int $debug_level
*
* @return bool
*/
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
{
$this->host = $host;
//If no port value provided, use default
if (false === $port) {
$this->port = static::DEFAULT_PORT;
} else {
$this->port = (int) $port;
}
//If no timeout value provided, use default
if (false === $timeout) {
$this->tval = static::DEFAULT_TIMEOUT;
} else {
$this->tval = (int) $timeout;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
//Reset the error log
$this->errors = [];
//Connect
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->login($this->username, $this->password);
if ($login_result) {
$this->disconnect();
return true;
}
}
//We need to disconnect regardless of whether the login succeeded
$this->disconnect();
return false;
}
/**
* Connect to a POP3 server.
*
* @param string $host
* @param int|bool $port
* @param int $tval
*
* @return bool
*/
public function connect($host, $port = false, $tval = 30)
{
//Are we already connected?
if ($this->connected) {
return true;
}
//On Windows this will raise a PHP Warning error if the hostname doesn't exist.
//Rather than suppress it with @fsockopen, capture it cleanly instead
set_error_handler(function () {
call_user_func_array([$this, 'catchWarning'], func_get_args());
});
if (false === $port) {
$port = static::DEFAULT_PORT;
}
//Connect to the POP3 server
$errno = 0;
$errstr = '';
$this->pop_conn = fsockopen(
$host, //POP3 Host
$port, //Port #
$errno, //Error Number
$errstr, //Error Message
$tval
); //Timeout (seconds)
//Restore the error handler
restore_error_handler();
//Did we connect?
if (false === $this->pop_conn) {
//It would appear not...
$this->setError(
"Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
);
return false;
}
//Increase the stream time-out
stream_set_timeout($this->pop_conn, $tval, 0);
//Get the POP3 server response
$pop3_response = $this->getResponse();
//Check for the +OK
if ($this->checkResponse($pop3_response)) {
//The connection is established and the POP3 server is talking
$this->connected = true;
return true;
}
return false;
}
/**
* Log in to the POP3 server.
* Does not support APOP (RFC 2828, 4949).
*
* @param string $username
* @param string $password
*
* @return bool
*/
public function login($username = '', $password = '')
{
if (!$this->connected) {
$this->setError('Not connected to POP3 server');
return false;
}
if (empty($username)) {
$username = $this->username;
}
if (empty($password)) {
$password = $this->password;
}
//Send the Username
$this->sendString("USER $username" . static::LE);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
//Send the Password
$this->sendString("PASS $password" . static::LE);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
}
}
return false;
}
/**
* Disconnect from the POP3 server.
*/
public function disconnect()
{
// If could not connect at all, no need to disconnect
if ($this->pop_conn === false) {
return;
}
$this->sendString('QUIT' . static::LE);
// RFC 1939 shows POP3 server sending a +OK response to the QUIT command.
// Try to get it. Ignore any failures here.
try {
$this->getResponse();
} catch (Exception $e) {
//Do nothing
}
//The QUIT command may cause the daemon to exit, which will kill our connection
//So ignore errors here
try {
@fclose($this->pop_conn);
} catch (Exception $e) {
//Do nothing
}
// Clean up attributes.
$this->connected = false;
$this->pop_conn = false;
}
/**
* Get a response from the POP3 server.
*
* @param int $size The maximum number of bytes to retrieve
*
* @return string
*/
protected function getResponse($size = 128)
{
$response = fgets($this->pop_conn, $size);
if ($this->do_debug >= self::DEBUG_SERVER) {
echo 'Server -> Client: ', $response;
}
return $response;
}
/**
* Send raw data to the POP3 server.
*
* @param string $string
*
* @return int
*/
protected function sendString($string)
{
if ($this->pop_conn) {
if ($this->do_debug >= self::DEBUG_CLIENT) { //Show client messages when debug >= 2
echo 'Client -> Server: ', $string;
}
return fwrite($this->pop_conn, $string, strlen($string));
}
return 0;
}
/**
* Checks the POP3 server response.
* Looks for for +OK or -ERR.
*
* @param string $string
*
* @return bool
*/
protected function checkResponse($string)
{
if (strpos($string, '+OK') !== 0) {
$this->setError("Server reported an error: $string");
return false;
}
return true;
}
/**
* Add an error to the internal error store.
* Also display debug output if it's enabled.
*
* @param string $error
*/
protected function setError($error)
{
$this->errors[] = $error;
if ($this->do_debug >= self::DEBUG_SERVER) {
echo '<pre>';
foreach ($this->errors as $e) {
print_r($e);
}
echo '</pre>';
}
}
/**
* Get an array of error messages, if any.
*
* @return array
*/
public function getErrors()
{
return $this->errors;
}
/**
* POP3 connection error handler.
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
*/
protected function catchWarning($errno, $errstr, $errfile, $errline)
{
$this->setError(
'Connecting to the POP3 server raised a PHP warning:' .
"errno: $errno errstr: $errstr; errfile: $errfile; errline: $errline"
);
}
}

1509
src/SMTP.php Normal file

File diff suppressed because it is too large Load Diff