Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$senderEmail = $_ENV['MAIL_USER'];
$senderAppPassword = $_ENV['MAIL_PASS'];
$recipientEmail = $_ENV['MAIL_RECIPIENT'];
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = htmlspecialchars($_POST["name"]);
$email = htmlspecialchars($_POST["email"]);
$message = htmlspecialchars($_POST["message"]);
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $senderEmail;
$mail->Password = $senderAppPassword;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom($senderEmail);
$mail->addAddress($recipientEmail);
$mail->addReplyTo($email);
// Content
$mail->isHTML(true);
$mail->Subject = 'Contact Form Submission';
$mail->Body = "<strong>Name:</strong> $name<br><strong>Email:</strong> $email<br><strong>Message:</strong><br>" . nl2br($message);
$mail->send();
echo json_encode(['success' => true]);
exit;
} catch (Exception $e) {
echo json_encode(['success' => false]);
exit;
}
} else {
echo json_encode(['success' => false]);
exit;
}