Fixed IMAP test button with error details

This commit is contained in:
johnnyq 2025-07-06 12:47:26 -04:00
parent ed0936059b
commit fa9acef279
2 changed files with 16 additions and 31 deletions

View File

@ -319,7 +319,7 @@ require_once "includes/inc_all_admin.php";
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>"> <input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
<div class="input-group-append"> <div class="input-group-append">
<button type="submit" name="test_email_imap" class="btn btn-success" disabled><i class="fas fa-fw fa-inbox mr-2"></i>Test (WIP)</button> <button type="submit" name="test_email_imap" class="btn btn-success"><i class="fas fa-fw fa-inbox mr-2"></i>Test</button>
</div> </div>
</form> </form>
</div> </div>

View File

@ -117,42 +117,27 @@ if (isset($_POST['test_email_smtp'])) {
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }
// Test IMAP
// Autoload Composer dependencies
// require_once __DIR__ . '/../plugins/php-imap/vendor/autoload.php';
// Webklex PHP-IMAP
//use Webklex\PHPIMAP\ClientManager;
if (isset($_POST['test_email_imap'])) { if (isset($_POST['test_email_imap'])) {
/* validateCSRFToken($_POST['csrf_token']);
validateCSRFToken($_POST['csrf_token']);
try { // Setup your IMAP connection parameters
// Initialize the client manager and create the client $hostname = "{" . $config_imap_host . ":" . $config_imap_port . "/" . $config_imap_encryption . "/novalidate-cert}INBOX";
$clientManager = new ClientManager(); $username = $config_imap_username;
$client = $clientManager->make([ $password = $config_imap_password;
'host' => $config_imap_host,
'port' => $config_imap_port,
'encryption' => $config_imap_encryption,
'validate_cert' => true,
'username' => $config_imap_username,
'password' => $config_imap_password,
'protocol' => 'imap'
]);
// Connect to the IMAP server try {
$client->connect(); $inbox = @imap_open($hostname, $username, $password);
if ($inbox) {
imap_close($inbox);
$_SESSION['alert_message'] = "Connected successfully"; $_SESSION['alert_message'] = "Connected successfully";
} catch (Exception $e) { } else {
$_SESSION['alert_type'] = "error"; throw new Exception(imap_last_error());
$_SESSION['alert_message'] = "Test IMAP connection failed: " . $e->getMessage();
} }
*/ } catch (Exception $e) {
$_SESSION['alert_message'] = "Test is Work In Progress"; $_SESSION['alert_type'] = "error";
$_SESSION['alert_message'] = "Test IMAP connection failed: " . $e->getMessage();
}
header("Location: " . $_SERVER["HTTP_REFERER"]); header("Location: " . $_SERVER["HTTP_REFERER"]);
} }