IMAP
"IMAP connection broken (server response)" is a PHP c-client error meaning the IMAP session dropped before login. Fix port/TLS, certs, and auth — here's how.
Updated Jul 1, 2026
The short answer
"[CLOSED] IMAP connection broken (server response)" is an error from PHP's IMAP (c-client/UW-IMAP) extension, not an RFC IMAP status code. It means imap_open() reached the server but the session dropped before login completed. Fix it by matching the port to the encryption (993 implicit SSL, 143 STARTTLS), correcting certificate/mailbox flags, and using modern auth (App Passwords for Gmail, OAuth for Exchange Online).
The full message is usually [CLOSED] IMAP connection broken (server response). Despite the wording, this is not an RFC 3501 IMAP server status or an SMTP reply code. It is an error string emitted by PHP's imap extension, which is built on the legacy UW-IMAP c-client library. You will see the identical text from anything that wraps that extension — ddeboer/imap, Kayako Classic's email parser, Faveo Helpdesk, and similar PHP mail tooling.
PHP 8.4+: the
imapextension was unbundled from PHP core and moved to PECL — it's no longer built in or enabled by default. Install it separately withpecl install imap, or migrate to a maintained library such aswebklex/php-imap.
[CLOSED] is the c-client mailbox state: the stream was opened but then closed. connection broken (server response) means the client got far enough to start talking to the server, but the session ended (the socket was reset, the TLS handshake failed, or the server rejected/aborted the session) before imap_open() could return a usable mailbox handle. So this is a connection-or-login failure, not a "mailbox not found" or "bad command" failure.
The connection reaches the server but does not survive to an authenticated session. The documented triggers are:
/novalidate-cert flag only skips certificate validation — it does not fix a handshake that never completes.outlook.office365.com:993 now requires OAuth 2.0; username + password will fail.1. Confirm what the server actually speaks. From a shell, test both modes:
# implicit TLS on 993openssl s_client -connect imap.example.com:993# STARTTLS on 143openssl s_client -starttls imap -connect imap.example.com:143
If 993 returns a TLS handshake and an * OK banner, use implicit SSL. If only 143 + STARTTLS works, use that. This also surfaces certificate errors directly.
2. Match the PHP connection flags to the result. For implicit TLS:
$mbox = imap_open('{imap.example.com:993/imap/ssl}', $user, $pass);
For STARTTLS on 143, use /imap/tls. Only add /novalidate-cert for a known self-signed cert in testing — never as a blind fix in production.
3. Use modern authentication.
imap.gmail.com:993 with /imap/ssl.imap extension supports XOAUTH2 only with a c-client built for it, so most teams move to an OAuth-capable IMAP client/library here.4. Rule out the network. Temporarily disable local firewall/antivirus or test from a different network to confirm a middlebox isn't closing the session.
5. Reconnect on transient drops. If the failure is intermittent (idle timeout, large mailbox), close the broken handle and re-open a fresh one rather than reusing it.
If none of these resolve it, the session is being terminated server-side — ask the mail-server admin to check the IMAP logs for the disconnect reason, which will name the real cause (auth failure, TLS error, or rate limit).
With Courier
References
FAQ
No. It is not an RFC 3501 IMAP status or an SMTP reply code. It is a string from PHP's imap extension (the UW-IMAP c-client library), meaning imap_open() reached the server but the session closed before login completed — typically a port/TLS mismatch, certificate failure, or rejected authentication.
One API, every provider
Courier connects to your email, SMS, and push providers, handles retries and failover, and surfaces delivery errors in plain language.
Last reviewed Jul 1, 2026. Courier is not affiliated with third-party providers; error behavior may vary by implementation.
© 2026 Courier. All rights reserved.