diff --git a/static/rsvp-submit.php b/static/rsvp-submit.php index b66c941..973b4fc 100755 --- a/static/rsvp-submit.php +++ b/static/rsvp-submit.php @@ -1,31 +1,37 @@ load(); +$dotenv = Dotenv::createImmutable(__DIR__ . '/../'); +$dotenv->safeLoad(); // Get form values -$name = $_POST['name'] ?? 'No Name'; +$first_name = $_POST['first_name'] ?? ''; +$last_name = $_POST['last_name'] ?? ''; +$name = trim("$first_name $last_name") ?: 'No Name'; + +// Drinks can be an array $drinks = $_POST['drinks'] ?? 'None'; +if (is_array($drinks)) { + $drinks = implode(', ', $drinks); +} + +// Allergies $allergies = $_POST['allergies'] ?? 'None'; -// Make sure UTF-8 +// Convert to UTF-8 $name = mb_convert_encoding($name, 'UTF-8', 'auto'); $drinks = mb_convert_encoding($drinks, 'UTF-8', 'auto'); $allergies = mb_convert_encoding($allergies, 'UTF-8', 'auto'); +// PHPMailer setup $mail = new PHPMailer(true); - try { $mail->CharSet = 'UTF-8'; $mail->isSMTP(); - $mail->SMTPDebug = 2; // debug output + $mail->SMTPDebug = 2; $mail->Debugoutput = 'html'; $mail->Host = $_ENV['SMTP_HOST']; $mail->SMTPAuth = true; @@ -37,9 +43,7 @@ try { $mail->setFrom($_ENV['FROM_EMAIL'], $_ENV['FROM_NAME']); $mail->addAddress($_ENV['TO_EMAIL']); - // Encode subject properly for UTF-8 - $subject = "New Wedding RSVP from $name"; - $mail->Subject = mb_encode_mimeheader($subject, 'UTF-8'); + $mail->Subject = mb_encode_mimeheader("New Wedding Guest: $name", 'UTF-8'); $body = <<Body = $body; - $mail->send(); + echo 'RSVP submitted successfully.'; } catch (Exception $e) { echo "RSVP could not be sent. Mailer Error: {$mail->ErrorInfo}";