Invalid access.
session_start(); // Always at the top
// ... [input validation and PHPMailer setup]
if (count($errors) === 0) {
$mail = new PHPMailer(true);
try {
// [PHPMailer SMTP setup, etc.]
$mail->send();
unset($_SESSION['phpmailer_debug']);
header("Location: index.php?success=1");
exit();
} catch (Exception $e) {
$_SESSION['form_errors'] = ["Could not send email. Mailer Error: {$mail->ErrorInfo}"];
// Add SMTP debug trace:
if (isset($_SESSION['phpmailer_debug'])) {
$_SESSION['form_errors'][] = implode("
", $_SESSION['phpmailer_debug']);
unset($_SESSION['phpmailer_debug']);
}
header("Location: index.php?success=0");
exit();
}
} else {
$_SESSION['form_errors'] = $errors;
header("Location: index.php?success=0");
exit();
}