Rewrote rsvp-submit.php again #2
This commit is contained in:
+15
-6
@@ -1,13 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
require __DIR__ . '/vendor/autoload.php'; // PHPMailer
|
require __DIR__ . '/../vendor/autoload.php'; // adjust path if needed
|
||||||
use PHPMailer\PHPMailer\PHPMailer;
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
use PHPMailer\PHPMailer\Exception;
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
// Load .env
|
// Load .env from /var/www/markinstefan.xyz/.env
|
||||||
if (!file_exists(__DIR__ . '/.env')) {
|
$envPath = '/var/www/markinstefan.xyz/.env';
|
||||||
|
if (!file_exists($envPath)) {
|
||||||
exit('Missing .env file!');
|
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
|
// Form validation
|
||||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit('Invalid request');
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit('Invalid request');
|
||||||
@@ -15,8 +23,8 @@ if (!empty($_POST['website'])) exit; // honeypot
|
|||||||
|
|
||||||
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
|
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
|
||||||
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
|
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
|
||||||
$drinks = isset($_POST['drinks']) ? implode(', ', $_POST['drinks']) : 'None';
|
$drinks = isset($_POST['drinks']) ? implode(', ', $_POST['drinks']) : 'None';
|
||||||
$allergies = htmlspecialchars($_POST['allergies'] ?? '');
|
$allergies = htmlspecialchars($_POST['allergies'] ?? '');
|
||||||
if (!$first_name || !$last_name) exit('Missing required fields');
|
if (!$first_name || !$last_name) exit('Missing required fields');
|
||||||
|
|
||||||
// Compose message
|
// Compose message
|
||||||
@@ -48,3 +56,4 @@ try {
|
|||||||
error_log("Mailer Error: {$mail->ErrorInfo}");
|
error_log("Mailer Error: {$mail->ErrorInfo}");
|
||||||
echo "Sorry, something went wrong. Please try again later.";
|
echo "Sorry, something went wrong. Please try again later.";
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user