Files
markinstefan.xyz/static/rsvp-submit.php
T
2026-05-16 23:38:33 +02:00

41 lines
1.1 KiB
PHP
Executable File

<?php
require __DIR__ . '/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$name = $_POST['name'] ?? 'No Name';
$drinks = $_POST['drinks'] ?? 'None';
$allergies = $_POST['allergies'] ?? 'None';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = $_ENV['SMTP_HOST'];
$mail->SMTPAuth = true;
$mail->Username = $_ENV['SMTP_USER'];
$mail->Password = $_ENV['SMTP_PASS'];
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = (int)$_ENV['SMTP_PORT'];
$mail->setFrom($_ENV['FROM_EMAIL'], $_ENV['FROM_NAME']);
$mail->addAddress($_ENV['TO_EMAIL']);
$mail->Subject = "New Wedding RSVP from $name";
if (!empty($_POST['email'])) {
$mail->addReplyTo($_POST['email'], $name);
}
$body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n";
$mail->Body = $body;
$mail->send();
echo 'RSVP submitted successfully.';
} catch (Exception $e) {
echo "RSVP could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>