59 lines
1.8 KiB
PHP
Executable File
59 lines
1.8 KiB
PHP
Executable File
<?php
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
require __DIR__ . '/vendor/autoload.php'; // <- same directory as rsvp-submit.php
|
|
|
|
// Load .env
|
|
$dotenvPath = __DIR__ . '/../.env';
|
|
if (!file_exists($dotenvPath)) {
|
|
exit("Missing .env file");
|
|
}
|
|
$env = parse_ini_file($dotenvPath, false, INI_SCANNER_RAW);
|
|
|
|
$SMTP_HOST = $env['SMTP_HOST'] ?? '';
|
|
$SMTP_PORT = $env['SMTP_PORT'] ?? 587;
|
|
$SMTP_USER = $env['SMTP_USER'] ?? '';
|
|
$SMTP_PASS = $env['SMTP_PASS'] ?? '';
|
|
$FROM_EMAIL = $env['FROM_EMAIL'] ?? '';
|
|
$FROM_NAME = $env['FROM_NAME'] ?? '';
|
|
$TO_EMAIL = $env['TO_EMAIL'] ?? '';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") exit("Invalid request");
|
|
|
|
// Honeypot
|
|
if (!empty($_POST['website'])) exit;
|
|
|
|
// Sanitize inputs
|
|
$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");
|
|
|
|
// Prepare email
|
|
$mail = new PHPMailer(true);
|
|
try {
|
|
$mail->isSMTP();
|
|
$mail->Host = $SMTP_HOST;
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $SMTP_USER;
|
|
$mail->Password = $SMTP_PASS;
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
|
$mail->Port = $SMTP_PORT;
|
|
|
|
$mail->setFrom($FROM_EMAIL, $FROM_NAME);
|
|
$mail->addAddress($TO_EMAIL);
|
|
|
|
// Email subject & body
|
|
$mail->Subject = "New Wedding Guest RSVP Form: $first_name $last_name";
|
|
$mail->Body = "Name: $first_name $last_name\nDrinks: $drinks\nAllergies: $allergies\n";
|
|
|
|
$mail->send();
|
|
echo "Thank you! Your RSVP has been sent.";
|
|
} catch (Exception $e) {
|
|
error_log("RSVP mail error: {$mail->ErrorInfo}");
|
|
echo "There was an error sending your RSVP. Please try again later.";
|
|
}
|