Specifications

We open the mailbox for a user account with a call to the open_mailbox() function that we
have written in mail_fns.php. This function is shown in Listing 27.9.
LISTING 27.9 open_mailbox() Function from mail_fns.phpThis Function Connects to a
User Mailbox
function open_mailbox($auth_user, $accountid)
{
// select mailbox if there is only one
if(number_of_accounts($auth_user)==1)
{
$accounts = get_account_list($auth_user);
$selected_account = $accounts[0];
session_register(“selected_account”);
$accountid = $selected_account;
}
// connect to the POP3 or IMAP server the user has selected
$settings = get_account_settings($auth_user, $accountid);
if(!sizeof($settings)) return 0;
$mailbox = “{“.$settings[server];
if($settings[type]==’POP3’)
$mailbox .= ‘/pop3’;
$mailbox .= “:”.$settings[port].”}INBOX”;
// suppress warning, remember to check return value
@ $imap = imap_open($mailbox, $settings[remoteuser],
$settings[remotepassword]);
return $imap;
}
We actually open the mailbox with the imap_open() function. This function has the following
prototype:
int imap_open (string mailbox, string username, string password [, int flags])
The parameters you need to pass to it are as follows:
mailboxThis string should contain the server name and mailbox name, and optionally
a port number and protocol. The format of this string is
{hostname/protocol:port}boxname
Building Practical PHP and MySQL Projects
P
ART V
642
33 7842 CH27 3/6/01 3:41 PM Page 642