Reverted rsvp-submit.php again #2

This commit is contained in:
spetznas
2026-05-16 23:04:29 +02:00
parent 7e7e473279
commit b111696c26
+35 -23
View File
@@ -1,38 +1,50 @@
<?php <?php
require __DIR__ . '/vendor/autoload.php'; // PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if ($_SERVER["REQUEST_METHOD"] !== "POST") { // Load .env
exit("Invalid request"); if (!file_exists(__DIR__ . '/.env')) {
exit('Missing .env file!');
} }
$dotenv = parse_ini_file(__DIR__ . '/.env', false, INI_SCANNER_RAW);
/* Honeypot spam protection */ // Form validation
if (!empty($_POST['website'])) { if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit('Invalid request');
exit; // silently drop bot submission if (!empty($_POST['website'])) exit; // honeypot
}
/* Safely read form fields */
$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) { // Compose message
exit("Missing required fields");
}
/* Email setup */
$to = "hochzeit@markinstefan.xyz";
$subject = "New Wedding RSVP from $first_name $last_name"; $subject = "New Wedding RSVP from $first_name $last_name";
$body = "Name: $first_name $last_name\n";
$body .= "Drinks: $drinks\n";
$body .= "Allergies: $allergies\n";
$message = "Name: $first_name $last_name\n"; // Send email via PHPMailer
$message .= "Drinks: $drinks\n"; $mail = new PHPMailer(true);
$message .= "Allergies: $allergies\n"; try {
$mail->isSMTP();
$mail->Host = $dotenv['SMTP_HOST'];
$mail->SMTPAuth = true;
$mail->Username = $dotenv['SMTP_USER'];
$mail->Password = $dotenv['SMTP_PASS'];
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = (int)$dotenv['SMTP_PORT'];
$headers = "From: no-reply@markinstefan.xyz\r\n"; $mail->setFrom($dotenv['FROM_EMAIL'], $dotenv['FROM_NAME']);
$headers .= "Reply-To: no-reply@markinstefan.xyz\r\n"; $mail->addAddress($dotenv['TO_EMAIL']);
/* Send mail */ $mail->Subject = $subject;
mail($to, $subject, $message, $headers); $mail->Body = $body;
$mail->send();
echo "Thank you! Your RSVP has been sent."; echo "Thank you! Your RSVP has been sent.";
?> } catch (Exception $e) {
error_log("Mailer Error: {$mail->ErrorInfo}");
echo "Sorry, something went wrong. Please try again later.";
}