Mail_IMAP::connect()

bool connect(string $uri[, bool $get_info = TRUE])

This method makes a connection to a mail server by calling on imap_open. This method accepts a URI abstraction in the following format: imap://user:pass@mail.example.com:143/INBOX#notls instead of the connection arguments used in imap_open. Replace the protocol with one of pop3|pop3s imap|imaps nntp|nntps. Place initial folder in the file path portion, and optionally append tls|notls|novalidate-cert in the anchor portion of the URI. A port number is optional, however, leaving it off could lead to a serious degradation in performance.

Since a URI syntax is used, internally Mail_IMAP::connect uses the PEAR Net_URL package to parse the URI. This package is required to use a URI syntax. Alternatively, Mail_IMAP::Mail_IMAP can accept an already formed imap stream.

Examples of a well-formed connection argument:

For IMAP: imap://user:pass@mail.example.com:143/INBOX

For IMAP SSL: imaps://user:pass@mail.example.com:993/INBOX

For POP3: pop3://user:pass@mail.example.com:110/INBOX

For POP3 SSL: pop3s://user:pass@mail.example.com:993/INBOX

For NNTP: nntp://user:pass@mail.example.com:119/comp.test

Adding TLS, NOTLS or NOVALIDATE-CERT:

Some servers may require a flag to signify that the connection is not encrypted with SSL or TLS. If this is the case then the NOTLS option may be required in the connection URI. On the other hand, you may want to signal the server to use TLS encryption specifically. These options may be added to the anchor portion of the URI syntax. This is also the likely place to append any undocumented connection options.

For NOTLS: imap://user:pass@mail.example.com:143/INBOX#notls

For TLS: imaps://user:pass@mail.example.com:143/INBOX#tls

TLS no-validate: imaps://user:pass@mail.example.com:143/INBOX#tls/novalidate-cert

SSL no-validate: imaps://user:pass@mail.example.com:143/INBOX#novalidate-cert

Usernames with special characters:

If the username is an email address or contains invalid or special URI characters, urlencode the username portion of the string before passing it. Use the IMAP.connection_wizard.php file to automatically detect the correct URI to pass to this function.

If the optional $get_info argument is TRUE, Mail_IMAP::connect automatically calls on Mail_IMAP::getMailboxInfo, whereas extra information about the mailbox is added to the $mailboxInfo

property.

Method summary:

param string $uri Server URI.
param int $get_info (optional) See above.
return bool
throws ErrorStack: Inclusion of Net_URL not successful. The Net_URL package is required to build a connection using a URI syntax. Verify that Net_URL is installed.
throws ErrorStack: Unable to build a connection to the specified mail server.. The remote server is either unavailable, or the settings passed in the URI are incorrect.
access public
see imap_open
Execution time: 0.09 seconds