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

51 lines
1.6 KiB
PHP
Executable File

<?php
require __DIR__ . '/vendor/autoload.php'; // PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load .env
if (!file_exists(__DIR__ . '/.env')) {
exit('Missing .env file!');
}
$dotenv = parse_ini_file(__DIR__ . '/.env', false, INI_SCANNER_RAW);
// Form validation
if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit('Invalid request');
if (!empty($_POST['website'])) exit; // honeypot
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
$drinks = isset($_POST['drinks']) ? implode(', ', $_POST['drinks']) : 'None';
$allergies = htmlspecialchars($_POST['allergies'] ?? '');
if (!$first_name || !$last_name) exit('Missing required fields');
// Compose message
$subject = "New Wedding RSVP from $first_name $last_name";
$body = "Name: $first_name $last_name\n";
$body .= "Drinks: $drinks\n";
$body .= "Allergies: $allergies\n";
// Send email via PHPMailer
$mail = new PHPMailer(true);
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'];
$mail->setFrom($dotenv['FROM_EMAIL'], $dotenv['FROM_NAME']);
$mail->addAddress($dotenv['TO_EMAIL']);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
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.";
}