   #PHP Manual IMAP, POP3 and NNTP functions imap_num_recent imap_ping

   PHP Manual
   Prev  Next
   ______________________________________________________________________

                                   imap_open

   (PHP 3, PHP 4 )
   imap_open -- Open an IMAP stream to a mailbox

Description

   resource imap_open ( string mailbox, string username, string password
   [, int options])

   Returns an IMAP stream on success and FALSE on error. This function
   can also be used to open streams to POP3 and NNTP servers, but some
   functions and features are only available on IMAP servers.

   A mailbox name consists of a server part and a mailbox path on this
   server. The special name INBOX stands for the current users personal
   mailbox. The server part, which is enclosed in '{' and '}', consists
   of the servers name or ip address, an optional port (prefixed by ':'),
   and an optional protocol specification (prefixed by '/'). The server
   part is mandatory in all mailbox parameters. Mailbox names that
   contain international characters besides those in the printable ASCII
   space have to be encoded with imap_utf7_encode().

   The options are a bit mask with one or more of the following:

     * OP_READONLY - Open mailbox read-only
     * OP_ANONYMOUS - Don't use or update a .newsrc for news (NNTP only)
     * OP_HALFOPEN - For IMAP and NNTP names, open a connection but don't
       open a mailbox
     * CL_EXPUNGE - Expunge mailbox automatically upon mailbox close

   To connect to an IMAP server running on port 143 on the local machine,
   do the following:

   <?php
   $mbox = imap_open("{localhost:143}INBOX", "user_id", "password");
   ?>

   To connect to a POP3 server on port 110 on the local server, use:

   <?php
   $mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id",
   "password");
   ?>

   To connect to an SSL IMAP or POP3 server, add /ssl after the protocol
   specification:

   <?php
   $mbox = imap_open ("{localhost:993/imap/ssl}INBOX", "user_id",
   "password");
   ?>

   To connect to an SSL IMAP or POP3 server with a self-signed
   certificate, add /ssl/novalidate-cert after the protocol
   specification:

   <?php
   $mbox = imap_open ("{localhost:995/pop3/ssl/novalidate-cert}",
   "user_id", "password");
   ?>

   To connect to an NNTP server on port 119 on the local server, use:

   <?php
   $nntp = imap_open ("{localhost:119/nntp}comp.test", "", "");
   ?>

   To connect to a remote server replace "localhost" with the name or the
   IP address of the server you want to connect to.

   Example 1. imap_open() example
   <?php
   $mbox = imap_open("{your.imap.host:143}", "username", "password");
   echo "<p><h1>Mailboxes</h1>\n";
   $folders = imap_listmailbox($mbox, "{your.imap.host:143}", "*");
   if ($folders == false) {
       echo "Call failed<br />\n";
   } else {
       while (list ($key, $val) = each($folders)) {
           echo $val . "<br />\n";
       }
   }
   echo "<p><h1>Headers in INBOX</h1>\n";
   $headers = imap_headers($mbox);
   if ($headers == false) {
       echo "Call failed<br />\n";
   } else {
       while (list ($key, $val) = each ($headers)) {
           echo $val . "<br />\n";
       }
   }
   imap_close($mbox);
   ?>
   ______________________________________________________________________

   Prev            Home      Next
   imap_num_recent  Up  imap_ping
