38 lines
1.1 KiB
PHP
Executable File
38 lines
1.1 KiB
PHP
Executable File
<?php
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); // <-- root .env
|
|
$dotenv->load();
|
|
|
|
$name = $_POST['name'] ?? 'No Name';
|
|
$drinks = $_POST['drinks'] ?? 'None';
|
|
$allergies = $_POST['allergies'] ?? 'None';
|
|
|
|
$mail = new PHPMailer(true);
|
|
|
|
try {
|
|
$mail->CharSet = 'UTF-8';
|
|
$mail->isSMTP();
|
|
$mail->SMTPDebug = 2; // debug mode
|
|
$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']);
|
|
$mail->Subject = "New Wedding RSVP from $name";
|
|
|
|
$mail->Body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n";
|
|
|
|
$mail->send();
|
|
echo 'RSVP submitted successfully.';
|
|
} catch (Exception $e) {
|
|
echo "RSVP could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
|
}
|