(PHP 4, PHP 5, PHP 7, PHP 8)

imap_msgnoGets the message sequence number for the given UID


imap_msgno(IMAP\Connection $imap, int $message_uid): int

Returns the message sequence number for the given message_uid.

This function is the inverse of imap_uid().



An IMAP\Connection instance.


The message UID

Return Values

Returns the message sequence number for the given message_uid.


Version Description
8.1.0 The imap parameter expects an IMAP\Connection instance now; previously, a valid imap resource was expected.

See Also

  • imap_uid() - This function returns the UID for the given message sequence number

add a note

User Contributed Notes 3 notes

phpdocu at malli dot co dot at
2 years ago
Here is a simple working snippet to properly check the return value of imap_msgno():

$id = imap_msgno($imapConnection, $mailUid); //convert to normal messagenumber in current context
$verifyUid = imap_uid($imapConnection, $id);
if ($verifyUid != $mailUid)
throw new Exception("Attention: imap_msgno returned nonsense! The mail was probably not found in the mailbox!");
os at simonconsulting dot at
13 years ago
For me, this function returns FALSE if uid does not match a message in the current mailbox.
22 years ago
<p>Note that imap_msgno() doesn't ever give you an error message. So, assuming you're passing about message numbers as a UID, be warned that:</p>
<p>$msguid = false;<br>
$msgno = imap_msgno( $your_initialized_connection, $msguid );</p>
<p>Will leave ($msgno==1) - this is probably not what you want, and it's surprisingly easy to miss while you're doing the basic testing.</p>
To Top