Added UTF-8 support to rsvp-submit.php #2

This commit is contained in:
spetznas
2026-05-16 23:45:24 +02:00
parent fceeeda68e
commit c518654da5
+5 -9
View File
@@ -3,7 +3,7 @@ require __DIR__ . '/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\Exception;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); // <-- root .env
$dotenv->load(); $dotenv->load();
$name = $_POST['name'] ?? 'No Name'; $name = $_POST['name'] ?? 'No Name';
@@ -13,8 +13,10 @@ $allergies = $_POST['allergies'] ?? 'None';
$mail = new PHPMailer(true); $mail = new PHPMailer(true);
try { try {
$mail->CharSet = 'UTF-8'; // <-- Make sure UTF-8 is used $mail->CharSet = 'UTF-8';
$mail->isSMTP(); $mail->isSMTP();
$mail->SMTPDebug = 2; // debug mode
$mail->Debugoutput = 'html';
$mail->Host = $_ENV['SMTP_HOST']; $mail->Host = $_ENV['SMTP_HOST'];
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
$mail->Username = $_ENV['SMTP_USER']; $mail->Username = $_ENV['SMTP_USER'];
@@ -26,16 +28,10 @@ try {
$mail->addAddress($_ENV['TO_EMAIL']); $mail->addAddress($_ENV['TO_EMAIL']);
$mail->Subject = "New Wedding RSVP from $name"; $mail->Subject = "New Wedding RSVP from $name";
if (!empty($_POST['email'])) { $mail->Body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n";
$mail->addReplyTo($_POST['email'], $name);
}
$body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n";
$mail->Body = $body;
$mail->send(); $mail->send();
echo 'RSVP submitted successfully.'; echo 'RSVP submitted successfully.';
} catch (Exception $e) { } catch (Exception $e) {
echo "RSVP could not be sent. Mailer Error: {$mail->ErrorInfo}"; echo "RSVP could not be sent. Mailer Error: {$mail->ErrorInfo}";
} }
?>