Updated rsvp-submit.php
This commit is contained in:
+47
-8
@@ -9,6 +9,17 @@ if (!empty($_POST['website'])) {
|
|||||||
exit; // silently drop bot submission
|
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 */
|
/* Safely read form fields */
|
||||||
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
|
$first_name = htmlspecialchars($_POST['first_name'] ?? '');
|
||||||
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
|
$last_name = htmlspecialchars($_POST['last_name'] ?? '');
|
||||||
@@ -20,19 +31,47 @@ if (!$first_name || !$last_name) {
|
|||||||
exit("Missing required fields");
|
exit("Missing required fields");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Email setup */
|
/* Build email content */
|
||||||
$to = "hochzeit@markinstefan.xyz";
|
$to = "hochzeit@markinstefan.xyz";
|
||||||
$subject = "New Wedding RSVP from $first_name $last_name";
|
$subject = "New Wedding RSVP from $first_name $last_name";
|
||||||
|
|
||||||
$message = "Name: $first_name $last_name\n";
|
$body = "New RSVP received:\n\n";
|
||||||
$message .= "Drinks: $drinks\n";
|
$body .= "Name: $first_name $last_name\n";
|
||||||
$message .= "Allergies: $allergies\n";
|
$body .= "Drinks: $drinks\n";
|
||||||
|
$body .= "Allergies: $allergies\n";
|
||||||
|
$body .= "Time: " . date("Y-m-d H:i:s") . "\n";
|
||||||
|
|
||||||
$headers = "From: no-reply@yourdomain.com\r\n";
|
/* Load PHPMailer */
|
||||||
$headers .= "Reply-To: no-reply@yourdomain.com\r\n";
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
/* Send mail */
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
mail($to, $subject, $message, $headers);
|
|
||||||
|
$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.";
|
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.");
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user