$email_from, 'from_name' => $email_from_name, 'recipient' => $email_to, 'recipient_name' => 'Chap', 'subject' => $subject, 'body' => $body ] ]; $mail = addToMailQueue($data); if ($mail === true) { $_SESSION['alert_message'] = "Test email queued! Check Admin > Mail queue"; } else { $_SESSION['alert_type'] = "error"; $_SESSION['alert_message'] = "Failed to add test mail to queue"; } header("Location: " . $_SERVER["HTTP_REFERER"]); } if (isset($_POST['test_email_imap'])) { validateCSRFToken($_POST['csrf_token']); // Setup your IMAP connection parameters $hostname = "{" . $config_imap_host . ":" . $config_imap_port . "/" . $config_imap_encryption . "/novalidate-cert}INBOX"; $username = $config_imap_username; $password = $config_imap_password; try { $inbox = @imap_open($hostname, $username, $password); if ($inbox) { imap_close($inbox); $_SESSION['alert_message'] = "Connected successfully"; } else { throw new Exception(imap_last_error()); } } catch (Exception $e) { $_SESSION['alert_type'] = "error"; $_SESSION['alert_message'] = "Test IMAP connection failed: " . $e->getMessage(); } header("Location: " . $_SERVER["HTTP_REFERER"]); }