PHP: IMAP - Manual
[/] Downloads Documentation Get Involved Help PHP 7.0.0 Released Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search (current page) / Focus search box Introduction » « cyrus_unbind PHP Manual Function Reference Mail Related Extensions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug IMAP, POP3 and NNTP Introduction Installing/Configuring Requirements Installation Runtime Configuration Resource Types Predefined Constants IMAP Functions imap_8bit — Convert an 8bit string to a quoted-printable string imap_alerts — Returns all IMAP alert messages that have occurred imap_append — Append a string message to a specified mailbox imap_base64 — Decode BASE64 encoded text imap_binary — Convert an 8bit string to a base64 string imap_body — Read the message body imap_bodystruct — Read the structure of a specified body section of a specific message imap_check — Check current mailbox imap_clearflag_full — Clears flags on messages imap_close — Close an IMAP stream imap_create — Alias of imap_createmailbox imap_createmailbox — Create a new mailbox imap_delete — Mark a message for deletion from current mailbox imap_deletemailbox — Delete a mailbox imap_errors — Returns all of the IMAP errors that have occurred imap_expunge — Delete all messages marked for deletion imap_fetch_overview — Read an overview of the information in the headers of the given message imap_fetchbody — Fetch a particular section of the body of the message imap_fetchheader — Returns header for a message imap_fetchmime — Fetch MIME headers for a particular section of the message imap_fetchstructure — Read the structure of a particular message imap_fetchtext — Alias of imap_body imap_gc — Clears IMAP cache imap_get_quota — Retrieve the quota level settings, and usage statics per mailbox imap_get_quotaroot — Retrieve the quota settings per user imap_getacl — Gets the ACL for a given mailbox imap_getmailboxes — Read the list of mailboxes, returning detailed information on each one imap_getsubscribed — List all the subscribed mailboxes imap_header — Alias of imap_headerinfo imap_headerinfo — Read the header of the message imap_headers — Returns headers for all messages in a mailbox imap_last_error — Gets the last IMAP error that occurred during this page request imap_list — Read the list of mailboxes imap_listmailbox — Alias of imap_list imap_listscan — Returns the list of mailboxes that matches the given text imap_listsubscribed — Alias of imap_lsub imap_lsub — List all the subscribed mailboxes imap_mail_compose — Create a MIME message based on given envelope and body sections imap_mail_copy — Copy specified messages to a mailbox imap_mail_move — Move specified messages to a mailbox imap_mail — Send an email message imap_mailboxmsginfo — Get information about the current mailbox imap_mime_header_decode — Decode MIME header elements imap_msgno — Gets the message sequence number for the given UID imap_num_msg — Gets the number of messages in the current mailbox imap_num_recent — Gets the number of recent messages in current mailbox imap_open — Open an IMAP stream to a mailbox imap_ping — Check if the IMAP stream is still active imap_qprint — Convert a quoted-printable string to an 8 bit string imap_rename — Alias of imap_renamemailbox imap_renamemailbox — Rename an old mailbox to new mailbox imap_reopen — Reopen IMAP stream to new mailbox imap_rfc822_parse_adrlist — Parses an address string imap_rfc822_parse_headers — Parse mail headers from a string imap_rfc822_write_address — Returns a properly formatted email address given the mailbox, host, and personal info imap_savebody — Save a specific body section to a file imap_scan — Alias of imap_listscan imap_scanmailbox — Alias of imap_listscan imap_search — This function returns an array of messages matching the given search criteria imap_set_quota — Sets a quota for a given mailbox imap_setacl — Sets the ACL for a given mailbox imap_setflag_full — Sets flags on messages imap_sort — Gets and sort messages imap_status — Returns status information on a mailbox imap_subscribe — Subscribe to a mailbox imap_thread — Returns a tree of threaded message imap_timeout — Set or fetch imap timeout imap_uid — This function returns the UID for the given message sequence number imap_undelete — Unmark the message which is marked deleted imap_unsubscribe — Unsubscribe from a mailbox imap_utf7_decode — Decodes a modified UTF-7 encoded string imap_utf7_encode — Converts ISO-8859-1 string to modified UTF-7 text imap_utf8 — Converts MIME-encoded text to UTF-8 add a note User Contributed Notes 3 notes up down 17 Wil Barath ¶ 5 years ago For all the people coming here praying for: 1) a dead-easy way to read MIME attachments, or 2) a dead-easy way to access POP3 folders Look no further. Nmsgs ; } $response = imap_fetch_overview ( $connection , $range ); foreach ( $response as $msg ) $result [ $msg -> msgno ]=(array) $msg ; return $result ; } function pop3_retr ( $connection , $message ) { return( imap_fetchheader ( $connection , $message , FT_PREFETCHTEXT )); } function pop3_dele ( $connection , $message ) { return( imap_delete ( $connection , $message )); } function mail_parse_headers ( $headers ) { $headers = preg_replace ( '/\r\n\s+/m' , '' , $headers ); preg_match_all ( '/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)?\r\n/m' , $headers , $matches ); foreach ( $matches [ 1 ] as $key => $value ) $result [ $value ]= $matches [ 2 ][ $key ]; return( $result ); } function mail_mime_to_array ( $imap , $mid , $parse_headers = false ) { $mail = imap_fetchstructure ( $imap , $mid ); $mail = mail_get_parts ( $imap , $mid , $mail , 0 ); if ( $parse_headers ) $mail [ 0 ][ "parsed" ]= mail_parse_headers ( $mail [ 0 ][ "data" ]); return( $mail ); } function mail_get_parts ( $imap , $mid , $part , $prefix ) { $attachments =array(); $attachments [ $prefix ]= mail_decode_part ( $imap , $mid , $part , $prefix ); if (isset( $part -> parts )) // multipart { $prefix = ( $prefix == "0" )? "" : " $prefix ." ; foreach ( $part -> parts as $number => $subpart ) $attachments = array_merge ( $attachments , mail_get_parts ( $imap , $mid , $subpart , $prefix .( $number + 1 ))); } return $attachments ; } function mail_decode_part ( $connection , $message_number , $part , $prefix ) { $attachment = array(); if( $part -> ifdparameters ) { foreach( $part -> dparameters as $object ) { $attachment [ strtolower ( $object -> attribute )]= $object -> value ; if( strtolower ( $object -> attribute ) == 'filename' ) { $attachment [ 'is_attachment' ] = true ; $attachment [ 'filename' ] = $object -> value ; } } } if( $part -> ifparameters ) { foreach( $part -> parameters as $object ) { $attachment [ strtolower ( $object -> attribute )]= $object -> value ; if( strtolower ( $object -> attribute ) == 'name' ) { $attachment [ 'is_attachment' ] = true ; $attachment [ 'name' ] = $object -> value ; } } } $attachment [ 'data' ] = imap_fetchbody ( $connection , $message_number , $prefix ); if( $part -> encoding == 3 ) { // 3 = BASE64 $attachment [ 'data' ] = base64_decode ( $attachment [ 'data' ]); } elseif( $part -> encoding == 4 ) { // 4 = QUOTED-PRINTABLE $attachment [ 'data' ] = quoted_printable_decode ( $attachment [ 'data' ]); } return( $attachment ); } ?> [EDIT BY danbrown AT php DOT net: Contains a bugfix by "mn26826" on 09-JUN-2010, which fixed the erroneous reference to $imap as the parameter passed to imap_mailboxmsginfo() within the user function pop3_stat(). This was intended to be $connection.] [EDIT BY visualmind AT php DOT net: Contains a bugfix by "elias-jobview" on 17-AUG-2010, which fixed the error in pop3_list function which didn't have: return $result] [EDIT BY danbrown AT php DOT net: Contains a bugfix by "chrismeistre" on 09-SEP-2010, which fixed the erroneous reference to $mbox (should be $connection) in the pop3_list() function.] up down 3 opto ¶ 3 years ago it seems that in new PHP versions, $ssl must be specified even if no ssl is used - I got it working for POP3 only after adding /notls (honour some post I found somewhere) Klaus up down -2 dev at bluehead dot com dot br ¶ 4 years ago Because I don't know regular expressions, I hacked the mail_parse_headers() to properly get the last line from the header string: $value ) $result [ $value ]= $matches [ 2 ][ $key ]; return( $result ); } ?> add a note Mail Related Extensions Cyrus IMAP Mail Mailparse vpopmail Copyright © 2001-2015 The PHP Group My PHP.net Contact Other PHP.net sites Mirror sites Privacy policy