Rewrote rsvp-submit.php again #6

This commit is contained in:
spetznas
2026-05-16 23:38:33 +02:00
parent 2a6cb3fbd0
commit eb925f2eab
+1 -8
View File
@@ -1,13 +1,11 @@
<?php <?php
require __DIR__ . '/vendor/autoload.php'; // PHPMailer autoload require __DIR__ . '/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\Exception;
// Load .env variables
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load(); $dotenv->load();
// Collect form data safely
$name = $_POST['name'] ?? 'No Name'; $name = $_POST['name'] ?? 'No Name';
$drinks = $_POST['drinks'] ?? 'None'; $drinks = $_POST['drinks'] ?? 'None';
$allergies = $_POST['allergies'] ?? 'None'; $allergies = $_POST['allergies'] ?? 'None';
@@ -15,7 +13,6 @@ $allergies = $_POST['allergies'] ?? 'None';
$mail = new PHPMailer(true); $mail = new PHPMailer(true);
try { try {
// SMTP configuration
$mail->isSMTP(); $mail->isSMTP();
$mail->Host = $_ENV['SMTP_HOST']; $mail->Host = $_ENV['SMTP_HOST'];
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
@@ -24,19 +21,15 @@ try {
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = (int)$_ENV['SMTP_PORT']; $mail->Port = (int)$_ENV['SMTP_PORT'];
// Email headers
$mail->setFrom($_ENV['FROM_EMAIL'], $_ENV['FROM_NAME']); $mail->setFrom($_ENV['FROM_EMAIL'], $_ENV['FROM_NAME']);
$mail->addAddress($_ENV['TO_EMAIL']); $mail->addAddress($_ENV['TO_EMAIL']);
$mail->Subject = "New Wedding RSVP from $name"; $mail->Subject = "New Wedding RSVP from $name";
// Optional: guest reply-to
if (!empty($_POST['email'])) { if (!empty($_POST['email'])) {
$mail->addReplyTo($_POST['email'], $name); $mail->addReplyTo($_POST['email'], $name);
} }
// Email body
$body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n"; $body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n";
$mail->Body = $body; $mail->Body = $body;
$mail->send(); $mail->send();