78 lines
1.9 KiB
PHP
Executable File
78 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
|
exit("Invalid request");
|
|
}
|
|
|
|
/* Honeypot spam protection */
|
|
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'] ?? '');
|
|
|
|
$drinks = isset($_POST['drinks']) ? implode(", ", $_POST['drinks']) : "None";
|
|
$allergies = htmlspecialchars($_POST['allergies'] ?? '');
|
|
|
|
if (!$first_name || !$last_name) {
|
|
exit("Missing required fields");
|
|
}
|
|
|
|
/* Build email content */
|
|
$to = "hochzeit@markinstefan.xyz";
|
|
$subject = "New Wedding RSVP from $first_name $last_name";
|
|
|
|
$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";
|
|
|
|
/* Load PHPMailer */
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
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.");
|
|
}
|
|
?>
|