imap_open
(PHP 4, PHP 5, PHP 7)
imap_open — Open an IMAP stream to a mailbox
Description
$mailbox
, string $username
, string $password
[, int $options
= 0
[, int $n_retries
= 0
[, array $params
= array()
]]] ) : resource
Opens an IMAP stream to a mailbox
.
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.
Parameters
-
mailbox
-
A mailbox name consists of a server and a mailbox path on this server. The special name INBOX 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 imap_utf7_encode().
WarningPassing untrusted data to this parameter is insecure, unless imap.enable_insecure_rsh is disabled.
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 "{" remote_system_name [":" port] [flags] "}" [mailbox_name] where:
- remote_system_name - Internet domain name or bracketed IP address of server.
- port - optional TCP port number, default is the default port for that service
- flags - optional flags, see following table.
- mailbox_name - remote mailbox name, default is INBOX
Optional flags for names Flag Description /service=service mailbox access service, default is "imap" /user=user remote user name for login on the server /authuser=user remote authentication user; if specified this is the user name whose password is used (e.g. administrator) /anonymous remote access as anonymous user /debug record protocol telemetry in application's debug log /secure do not transmit a plaintext password over the network /imap, /imap2, /imap2bis, /imap4, /imap4rev1 equivalent to /service=imap /pop3 equivalent to /service=pop3 /nntp equivalent to /service=nntp /norsh do not use rsh or ssh to establish a preauthenticated IMAP session /ssl use the Secure Socket Layer to encrypt the session /validate-cert validate certificates from TLS/SSL server (this is the default behavior) /novalidate-cert do not validate certificates from TLS/SSL server, needed if server uses self-signed certificates /tls force use of start-TLS to encrypt the session, and reject connection to servers that do not support it /notls do not do start-TLS to encrypt the session, even with servers that support it /readonly request read-only mailbox open (IMAP only; ignored on NNTP, and an error with SMTP and POP3) -
username
-
The user name
-
password
-
The password associated with the
username
-
options
-
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 (see also imap_delete() and imap_expunge()) -
OP_DEBUG
- Debug protocol negotiations -
OP_SHORTCACHE
- Short (elt-only) caching -
OP_SILENT
- Don't pass up events (internal use) -
OP_PROTOTYPE
- Return driver prototype -
OP_SECURE
- Don't do non-secure authentication
-
-
n_retries
-
Number of maximum connect attempts
-
params
-
Connection parameters, the following (string) keys maybe used to set one or more connection parameters:
- DISABLE_AUTHENTICATOR - Disable authentication properties
Examples
Example #1 Different use of imap_open()
<?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.
?>
Example #2 imap_open() 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);
?>
Vertaling niet beschikbaar
De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.
Als je de moed voelt, kun je je vertaling aanbieden ;-)
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-function.imap-open.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.