Updated rsvp-submit.php

This commit is contained in:
spetznas
2026-05-16 22:47:53 +02:00
parent 838dabccca
commit 7a9232b992
+47 -8
View File
@@ -9,6 +9,17 @@ if (!empty($_POST['website'])) {
exit; // silently drop bot submission
}
/* Load environment variables (your Option 1) */
$env = parse_ini_file('/etc/wedding.env');
$smtpUser = $env['SMTP_USER'] ?? null;
$smtpPass = $env['SMTP_PASS'] ?? null;
$smtpHost = $env['SMTP_HOST'] ?? 'posteo.de';
if (!$smtpUser || !$smtpPass) {
exit("Server misconfiguration (missing SMTP credentials)");
}
/* Safely read form fields */
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
@@ -20,19 +31,47 @@ if (!$first_name || !$last_name) {
exit("Missing required fields");
}
/* Email setup */
/* Build email content */
$to = "hochzeit@markinstefan.xyz";
$subject = "New Wedding RSVP from $first_name $last_name";
$message = "Name: $first_name $last_name\n";
$message .= "Drinks: $drinks\n";
$message .= "Allergies: $allergies\n";
$body = "New RSVP received:\n\n";
$body .= "Name: $first_name $last_name\n";
$body .= "Drinks: $drinks\n";
$body .= "Allergies: $allergies\n";
$body .= "Time: " . date("Y-m-d H:i:s") . "\n";
$headers = "From: no-reply@yourdomain.com\r\n";
$headers .= "Reply-To: no-reply@yourdomain.com\r\n";
/* Load PHPMailer */
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
/* Send mail */
mail($to, $subject, $message, $headers);
require __DIR__ . '/vendor/autoload.php';
$mail = new PHPMailer(true);
try {
/* SMTP config */
$mail->isSMTP();
$mail->Host = $smtpHost;
$mail->SMTPAuth = true;
$mail->Username = $smtpUser;
$mail->Password = $smtpPass;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
/* Email headers */
$mail->setFrom($smtpUser, 'Wedding RSVP');
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
echo "Thank you! Your RSVP has been sent.";
} catch (Exception $e) {
error_log("RSVP mail failed: " . $mail->ErrorInfo);
exit("Sorry, something went wrong sending your RSVP.");
}
?>