Rewrote rsvp-submit.php again #2

This commit is contained in:
spetznas
2026-05-16 23:08:43 +02:00
parent b111696c26
commit 7ce7b4f179
+15 -6
View File
@@ -1,13 +1,21 @@
<?php
require __DIR__ . '/vendor/autoload.php'; // PHPMailer
require __DIR__ . '/../vendor/autoload.php'; // adjust path if needed
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load .env
if (!file_exists(__DIR__ . '/.env')) {
// Load .env from /var/www/markinstefan.xyz/.env
$envPath = '/var/www/markinstefan.xyz/.env';
if (!file_exists($envPath)) {
exit('Missing .env file!');
}
$dotenv = parse_ini_file(__DIR__ . '/.env', false, INI_SCANNER_RAW);
// Simple parser for key=value lines
$dotenv = [];
foreach (file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
if (preg_match('/^\s*([A-Z_]+)\s*=\s*(.*)\s*$/', $line, $matches)) {
$dotenv[$matches[1]] = trim($matches[2], "\"'");
}
}
// Form validation
if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit('Invalid request');
@@ -15,8 +23,8 @@ if (!empty($_POST['website'])) exit; // honeypot
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
$drinks = isset($_POST['drinks']) ? implode(', ', $_POST['drinks']) : 'None';
$allergies = htmlspecialchars($_POST['allergies'] ?? '');
$drinks = isset($_POST['drinks']) ? implode(', ', $_POST['drinks']) : 'None';
$allergies = htmlspecialchars($_POST['allergies'] ?? '');
if (!$first_name || !$last_name) exit('Missing required fields');
// Compose message
@@ -48,3 +56,4 @@ try {
error_log("Mailer Error: {$mail->ErrorInfo}");
echo "Sorry, something went wrong. Please try again later.";
}
?>