{source}
/**
* PHP script to connect to an IMAP mail server, list mailboxes under the
* INBOX, and report the total number of emails in each. This script is
* designed to be embedded in a Joomla article or module using a "PHP in Content" plugin.
*/
// --- USER CONFIGURATION ---
// Replace these with your actual server and login details.
$server = 'deprise.com';
$port = 993;
$username =
$password = 'Deprise753!';
// --- SCRIPT LOGIC ---
$html_output = '
';
$html_output .= '
Mailbox Status
';
if ($server == 'imap.your-mail-server.com' || $username ==
$html_output .= '
Please edit the script with your IMAP server details and credentials.
';
} else {
$connection_string = "{" . $server . ":" . $port . "/imap/ssl/novalidate-cert}INBOX";
$imap_stream = @imap_open($connection_string, $username, $password);
if ($imap_stream === false) {
$errors = imap_errors();
$error_message = $errors ? implode(", ", $errors) : "Unknown reason. Please check your credentials and server address.";
$html_output .= '
Connection failed. Error: ' . htmlspecialchars($error_message) . '
';
} else {
$html_output .= '
Connection successful. Listing mailboxes...
';
$all_mailboxes = imap_list($imap_stream, "{" . $server . ":" . $port . "/imap/ssl}", "*");
if ($all_mailboxes === false) {
$html_output .= '
Failed to list mailboxes.
';
} else {
$html_output .= '
';
$found_count = 0;
foreach ($all_mailboxes as $mailbox) {
$folder_name = imap_utf7_decode(str_replace("{" . $server . ":" . $port . "/imap/ssl}", "", $mailbox));
if (strpos(strtoupper($folder_name), 'INBOX') === 0) {
$found_count++;
$status = imap_status($imap_stream, $mailbox, SA_MESSAGES);
if ($status) {
$total_emails = $status->messages;
$html_output .= '
- ' . htmlspecialchars($folder_name) . ': ' . $total_emails . ' emails
';
} else {
$html_output .= '
- ' . htmlspecialchars($folder_name) . ': Could not retrieve status.
';
}
}
}
$html_output .= '
';
if ($found_count === 0) {
$html_output .= '
No mailboxes found under INBOX.
';
}
}
imap_close($imap_stream);
$html_output .= '
Connection closed.
';
}
}
$html_output .= '
';
echo $html_output;
?>
{/source}