Received POST Data:";
echo "
";
foreach ($_POST as $key => $value) {
$columns[] = "`" . $conn->real_escape_string($key) . "`";
$values[] = "'" . $conn->real_escape_string($value) . "'";
echo "- " . htmlspecialchars($key) . ": " . htmlspecialchars($value) . "
";
}
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 "Data successfully inserted into database with id = " . $lastId . "
";
if (!empty($_POST['email'])) {
echo "Email is set to " . $_POST['email'];
generatePprEmail($lastId);
} else {
echo "Username is not set.";
}
//echo '';
} else {
echo "Error inserting data: " . $conn->error . "
";
}
}
echo "
";
} else {
echo "No POST data received.
";
}
function generatePprEmail($entryId) {
global $mailHost, $mailSMTPAuth, $mailUsername, $mailPassword, $mailPort, $baseUrl, $mailFromAddress, $mailFromName;
$token = generateSecureToken($_POST['email'], $entryId);
$secureLink = $baseUrl . "/pilotppr.php?op=view&token=" . urlencode($token);
echo $secureLink;
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = $mailHost;
$mail->SMTPAuth = $mailSMTPAuth;
$mail->Username = $mailUsername;
$mail->Password = $mailPassword;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = $mailPort;
$mail->setFrom($mailFromAddress, $mailFromName);
$mail->addAddress($_POST['email']);
$mail->isHTML(true);
$mail->Subject = "PPR Confirmation";
$mail->Body = "
This is to confirm we have received your PPR. To view or cancel your PPR please click the button:
Edit Entry
";
$mail->send();
echo "Email sent successfully!";
} catch (Exception $e) {
echo "Email sending failed: {$mail->ErrorInfo}";
}
}
?>