Specifications

If the protocol is not specified, it defaults to IMAP. In the code we have written, you can
see that we specify POP3 if the user has specified that protocol for a particular account.
For example, to read mail from the local machine using the default ports, we would use
the following mailbox name for IMAP
{localhost:143}INBOX
and this one for POP3
{localhost/pop3:110}INBOX
usernameThe username for the account
passwordThe password for the account
You can also pass it optional flags to specify options such as “open mailbox in read-only
mode”
.
One thing to note is that we have constructed the mailbox string piece by piece with the con-
catenation operator before passing it to
imap_open(). You need to be careful how you construct
this string because strings containing {$ cause problems in PHP 4.
This function call returns an IMAP stream if the mailbox can be opened, and false if it cannot.
When you are finished with an IMAP stream, you can close it using imap_close(imap_stream).
In our function, the IMAP stream is passed back to the main program. We then use the
imap_headers() function to get the email headers for display:
$headers = imap_headers($imap);
This function returns header information for all mail messages in the mailbox we have con-
nected to. The information is returned as an array, one line per message. We havent formatted
this. It just outputs one line per message, so you can see from looking at Figure 27.5 what the
output looks like.
You can get more information about email headers using the confusing, similarly named
imap_header(). In this case, the imap_headers() function gives us enough detail for our
purpose.
Reading a Mail Message
We have set up each of the messages in the previous display_list() function to link to
specific email messages.
Each link is of the form
index.php?action=view-message&messageid=6
Building a Web-Based Email Service
C
HAPTER 27
27
BUILDING A
WEB-BASED
EMAIL
SERVICE
643
33 7842 CH27 3/6/01 3:41 PM Page 643