PHP.nl

imap_open

imap_open

Open an IMAP stream to a mailbox

 **imap_open** string $mailbox string $user string $password int $flags int $retries array $options

Opens an stream to a . mailbox

This function can also be used to open streams to and servers, but some functions and features are only available on servers.

mailbox A mailbox name consists of a server and a mailbox path on this server. The special name stands for the current users personal mailbox. Mailbox names that contain international characters besides those in the printable ASCII space have to be encoded with . INBOX``imap_utf7_encode

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.

   All names which start with  are remote names, and are
   in the form  where:
   
  `{``"{" remote_system_name [":" port] [flags] "}"
   [mailbox_name]`- - Internet domain name or           bracketed IP address of server.          `remote_system_name`
    • optional TCP port number, default is the default port for that service port
    • optional flags, see following table. flags
    • remote mailbox name, default is INBOX mailbox_name

userThe user name

password The password associated with the user

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

  `flags`- - Open mailbox read-only          `OP_READONLY`
    • Don't use or update a for news (NNTP only) OP_ANONYMOUS
    • For and names, open a connection but don't open a mailbox. OP_HALFOPEN
    • Expunge mailbox automatically upon mailbox close (see also and ) CL_EXPUNGE``imap_delete``imap_expunge
    • Debug protocol negotiations OP_DEBUG
    • Short (-only) caching OP_SHORTCACHE``elt
    • Don't pass up events (internal use) OP_SILENT
    • Return driver prototype OP_PROTOTYPE
    • Don't do non-secure authentication OP_SECURE

retriesNumber of maximum connect attempts

options Connection parameters, the following (string) keys maybe used to set one or more connection parameters:

  - - Disable authentication properties          `DISABLE_AUTHENTICATOR`

Returns an instance on success,return.falseforfailure. IMAP\Connection

**Voorbeeld: Different use of **

<?php
// To connect to an IMAP server running on port 143 on the local machine,
// do the following:
$mbox = imap_open("{localhost:143}INBOX", "user_id", "password");

// To connect to a POP3 server on port 110 on the local server, use:
$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:
$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:
$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:
$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.
?>

Voorbeeld: example

<?php
$mbox = imap_open("{imap.example.org:143}", "username", "password");

echo "<h1>Mailboxes</h1>\n";
$folders = imap_listmailbox($mbox, "{imap.example.org:143}", "*");

if ($folders == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />\n";
    }
}

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);
?>

imap_close