load(); // Get form values $name = $_POST['name'] ?? 'No Name'; $drinks = $_POST['drinks'] ?? 'None'; $allergies = $_POST['allergies'] ?? 'None'; // Make sure 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'); $mail = new PHPMailer(true); try { $mail->CharSet = 'UTF-8'; $mail->isSMTP(); $mail->SMTPDebug = 2; // debug output $mail->Debugoutput = 'html'; $mail->Host = $_ENV['SMTP_HOST']; $mail->SMTPAuth = true; $mail->Username = $_ENV['SMTP_USER']; $mail->Password = $_ENV['SMTP_PASS']; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = (int)$_ENV['SMTP_PORT']; $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'); $body = <<Body = $body; $mail->send(); echo 'RSVP submitted successfully.'; } catch (Exception $e) { echo "RSVP could not be sent. Mailer Error: {$mail->ErrorInfo}"; }