Added UTF-8 support to rsvp-submit.php #3
This commit is contained in:
+19
-4
@@ -3,19 +3,25 @@ require __DIR__ . '/vendor/autoload.php';
|
|||||||
use PHPMailer\PHPMailer\PHPMailer;
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
use PHPMailer\PHPMailer\Exception;
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); // <-- root .env
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); // root .env
|
||||||
$dotenv->load();
|
$dotenv->load();
|
||||||
|
|
||||||
|
// Get form values
|
||||||
$name = $_POST['name'] ?? 'No Name';
|
$name = $_POST['name'] ?? 'No Name';
|
||||||
$drinks = $_POST['drinks'] ?? 'None';
|
$drinks = $_POST['drinks'] ?? 'None';
|
||||||
$allergies = $_POST['allergies'] ?? '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);
|
$mail = new PHPMailer(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$mail->CharSet = 'UTF-8';
|
$mail->CharSet = 'UTF-8';
|
||||||
$mail->isSMTP();
|
$mail->isSMTP();
|
||||||
$mail->SMTPDebug = 2; // debug mode
|
$mail->SMTPDebug = 2; // debug output
|
||||||
$mail->Debugoutput = 'html';
|
$mail->Debugoutput = 'html';
|
||||||
$mail->Host = $_ENV['SMTP_HOST'];
|
$mail->Host = $_ENV['SMTP_HOST'];
|
||||||
$mail->SMTPAuth = true;
|
$mail->SMTPAuth = true;
|
||||||
@@ -26,9 +32,18 @@ try {
|
|||||||
|
|
||||||
$mail->setFrom($_ENV['FROM_EMAIL'], $_ENV['FROM_NAME']);
|
$mail->setFrom($_ENV['FROM_EMAIL'], $_ENV['FROM_NAME']);
|
||||||
$mail->addAddress($_ENV['TO_EMAIL']);
|
$mail->addAddress($_ENV['TO_EMAIL']);
|
||||||
$mail->Subject = "New Wedding RSVP from $name";
|
|
||||||
|
|
||||||
$mail->Body = "Name: $name\nDrinks: $drinks\nAllergies: $allergies\n";
|
// Encode subject properly for UTF-8
|
||||||
|
$subject = "New Wedding RSVP from $name";
|
||||||
|
$mail->Subject = mb_encode_mimeheader($subject, 'UTF-8');
|
||||||
|
|
||||||
|
$body = <<<EOD
|
||||||
|
Name: $name
|
||||||
|
Drinks: $drinks
|
||||||
|
Allergies: $allergies
|
||||||
|
EOD;
|
||||||
|
|
||||||
|
$mail->Body = $body;
|
||||||
|
|
||||||
$mail->send();
|
$mail->send();
|
||||||
echo 'RSVP submitted successfully.';
|
echo 'RSVP submitted successfully.';
|
||||||
|
|||||||
Reference in New Issue
Block a user