15.1 Opening an IMAP Mailbox


You want to open a stream to an IMAP mailbox. This technique can also be used when accessing POP or NNTP mailboxes.

Technique

Use the imap_open() function, which enables you to open a stream to a POP, NNTP, or IMAP server. To open a connection to an IMAP server, do the following:

 <?php $mh = imap_open("{servername.com:143}INBOX", $user, $pass); ?> 

To open a connection to a POP server, simply specify it in the syntax of the first argument:

 <?php $mh = imap_open("{servername.com/pop3:110}INBOX", $user, $pass); ?> 

The same thing applies when accessing an NNTP server:

 <?php $nh = imap_open("{servername.com/nntp:119}comp.lang.perl.misc",                 $username, $password ); ?> 

Comments

The imap_open() function takes as its first argument the mailbox name. The server part of the mailbox name , enclosed in { and } , consists of the server name, a protocol specification that is separated from the server name with / , and an optional port specifier beginning with : . The second and third arguments to imap_open() are your username and passwords, respectively.

imap_open() is the only place where you need to distinguish between server types (that is, nntp or pop3 ). You can manipulate the stream returned by imap_open() with any of the appropriate imap_* functions. Of course, because of the difference in the types of programs, some functions will not work with different server types.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net