For those using a POP3 mailbox, this function, as noted, does not work.
One way around this is to use direct FTP communication with the mail server. For example, the following function takes a mailbox/password and message sequence number, and from this returns the message UID.
function fetch_UID($account, $password, $message_number)
{
$retval = 0;
$fp = fsockopen($POPMAILSERVER, 110);
if ($fp > 0)
{
$buf = fgets($fp, 1024);
fputs($fp, "USER ".$account."\n");
$buf = fgets($fp, 1024);
fputs($fp, "PASS ".$password."\n");
$buf = fgets($fp, 1024);
fputs($fp, "UIDL ".$message_number."\n");
$retval=fgets($fp, 1024);
fputs($fp, "QUIT\n");
$buf = fgets($fp,1024);
fclose($fp);
}
return substr($retval,6,30);
}
Note: 110 is the TCP port commonly associated with a POP3 mailbox. Also the substr() function is used to trim the +OK and the message number from the beginning of the server's response.
I'm sure there are other (better) ways to do this. But after a fruitless search of the internet, this is what I came up with, and it seems to work for me.