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

60 lines
1.9 KiB
PHP
Executable File

<?php
require __DIR__ . '/vendor/autoload.php'; // adjust path if needed
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load .env from /var/www/markinstefan.xyz/.env
$envPath = '/var/www/markinstefan.xyz/.env';
if (!file_exists($envPath)) {
exit('Missing .env file!');
}
// Simple parser for key=value lines
$dotenv = [];
foreach (file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
if (preg_match('/^\s*([A-Z_]+)\s*=\s*(.*)\s*$/', $line, $matches)) {
$dotenv[$matches[1]] = trim($matches[2], "\"'");
}
}
// 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.";
}
?>