Email PPR
This commit is contained in:
52
newppr.php
52
newppr.php
@@ -1,4 +1,10 @@
|
||||
<?php
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
include("functions.php");
|
||||
require_db_auth();
|
||||
|
||||
@@ -21,8 +27,16 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
echo $sql;
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "<p>Data successfully inserted into database.</p>";
|
||||
echo '<script>window.close();</script>';
|
||||
$lastId = $conn->insert_id;
|
||||
echo "<p>Data successfully inserted into database with id = " . $lastId . "</p>";
|
||||
if (!empty($_POST['email'])) {
|
||||
echo "Email is set to " . $_POST['email'];
|
||||
generatePprEmail($lastId);
|
||||
} else {
|
||||
echo "Username is not set.";
|
||||
}
|
||||
|
||||
//echo '<script>window.close();</script>';
|
||||
} else {
|
||||
echo "<p>Error inserting data: " . $conn->error . "</p>";
|
||||
}
|
||||
@@ -32,5 +46,39 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
echo "<h2>No POST data received.</h2>";
|
||||
}
|
||||
|
||||
function generatePprEmail($entryId) {
|
||||
$token = generateSecureToken($_POST['email'], $entryId);
|
||||
$secureLink = "https://ppr.swansea-airport.wales/dev/cancelppr.php?op=view&token=" . urlencode($token);
|
||||
echo $secureLink;
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'send.one.com'; // Your SMTP server
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = 'noreply@swansea-airport.wales';
|
||||
$mail->Password = 'SASAGoForward2155';
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$mail->Port = 465;
|
||||
|
||||
$mail->setFrom('noreply@swansea-airport.wales', 'Swansea Airport');
|
||||
$mail->addAddress($_POST['email']);
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = "Edit Your Entry";
|
||||
$mail->Body = "
|
||||
<p>Click the button below to edit your entry securely:</p>
|
||||
<a href='$secureLink' style='display: inline-block; padding: 10px 20px; color: white; background-color: #007bff; text-decoration: none; border-radius: 5px;'>Edit Entry</a>
|
||||
";
|
||||
|
||||
$mail->send();
|
||||
echo "Email sent successfully!";
|
||||
} catch (Exception $e) {
|
||||
echo "Email sending failed: {$mail->ErrorInfo}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user