Files
ppr/newppr.php
2025-03-07 18:38:47 +00:00

85 lines
2.6 KiB
PHP

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
include("functions.php");
require_db_auth();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$conn = connectDb();
$columns = [];
$values = [];
echo "<h2>Received POST Data:</h2>";
echo "<ul>";
foreach ($_POST as $key => $value) {
$columns[] = "`" . $conn->real_escape_string($key) . "`";
$values[] = "'" . $conn->real_escape_string($value) . "'";
echo "<li><strong>" . htmlspecialchars($key) . ":</strong> " . htmlspecialchars($value) . "</li>";
}
if (!empty($columns)) {
$sql = "INSERT INTO submitted (created_by, " . implode(",", $columns) . ") VALUES ('" . $_SERVER['PHP_AUTH_USER'] . "'," . implode(",", $values) . ")";
echo $sql;
if ($conn->query($sql) === TRUE) {
$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>";
}
}
echo "</ul>";
} else {
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}";
}
}
?>