Connecting to a mailbox

suggest change

To do anything with an IMAP account you need to connect to it first. To do this you need to specify some required parameters:

- IMAP is 143 or 993 (secure)
- POP is 110 or 995 (secure)
- SMTP is 25 or 465 (secure)
- NNTP is 119 or 563 (secure)

Flag | Description | Options | Default | —— | —— | —— | —— |/service=service | Which service to use | imap, pop3, nntp, smtp | 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 | | disabled |/secure | do not transmit a plaintext password over the network | | |/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 | certificates from TLS/SSL server | | enabled |/novalidate-cert | do not validate certificates from TLS/SSL server, needed if server uses self-signed certificates. USE WITH CAUTION | | disabled |/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)

Your connection string will look something like this:

{imap.example.com:993/imap/tls/secure}

Please note that if any of the characters in your connection string is non-ASCII it must be encoded with utf7_encode($string).

To connect to the mailbox, we use the imap_open command which returns a resource value pointing to a stream:

<?php
$mailbox = imap_open("{imap.example.com:993/imap/tls/secure}", "username", "password");
if ($mailbox === false) {
    echo "Failed to connect to server";
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


IMAP:
* IMAP
* Connecting to a mailbox

Table Of Contents
2 Arrays
4 Types
10 Cookies
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
87 MongoDB
93 IMAP
94 Redis
95 Imagick
102 APCu
108 PSR