fix: add pre-check if imap is supported before trying to connect

This commit is contained in:
idevakk
2025-11-09 03:25:59 -08:00
parent 391af8a778
commit 664637fa30

View File

@@ -502,11 +502,28 @@ class Settings extends Page implements HasForms
private function testIMAP($imap): bool
{
try {
// First check if IMAP extension is available
if (!function_exists('imap_open')) {
Notification::make()
->title('IMAP Extension Not Available')
->body('The PHP IMAP extension is not loaded in your web server. Please check your Herd PHP configuration or restart your server.')
->danger()
->send();
return false;
}
ZEmail::connectMailBox($imap);
return true;
} catch (\Exception $exception) {
$errorMessage = $exception->getMessage();
// Provide more helpful error messages
if (str_contains($errorMessage, 'IMAP extension must be enabled')) {
$errorMessage = 'IMAP extension is not properly loaded in the web server. Try restarting Herd or check your PHP configuration.';
}
Notification::make()
->title('Imap Error : '.$exception->getMessage())
->title('IMAP Error: ' . $errorMessage)
->danger()
->send();
return false;