What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



imap_search — Searches the specified mailbox based on search criteria


array imap_search(connection, searchtext, flags);
int connection: IMAP connection ID
string searchtext: Text to search for in mailbox
int flags: Flags allowing additional functionality


An array of messages


Similar to imap_scanmailbox() except this function searchs only the current mailbox and the search criteria is able to be specified. The search criteria specified by searchtext is deliminated by spaces and if multiworded arguments are required, they must be enclosed in quote marks.

Prepended to user defined search strings in searchtext is an argument specifying which messages and message parts are to be search. These are:

ALL Return all messages matching the rest of the criteria
ANSWERED Match messages with the \\ANSWERED flag set
BCC Match messages with searchtext in the Bcc: field
BEFORE Match messages with Date: before searchtext
BODY Match messages with searchtext " in the body of the message
CC Match messages with searchtext in the Cc: field
DELETED Match deleted messages
FLAGGED Match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
FROM Match messages with searchtext in the From: field
KEYWORD Match messages with searchtext as a keyword
NEW Match new messages
OLD Match old messages
ON Match messages with Date: matching searchtext
RECENT Match messages with the \\RECENT flag set
SEEN Match messages that have been read (the \\SEEN flag is set)
SINCE Match messages with Date: after searchtext
SUBJECT Match messages with searchtext in the Subject
TEXT Match messages with text searchtext
TO Match messages with searchtext in the To: field
UNANSWERED Match messages that have not been answered
UNDELETED Match messages that are not deleted
UNFLAGGED Match messages that are not flagged
UNKEYWORD Match messages that do not have the keyword searchtext
UNSEEN Match messages which have not been read yet

The only possible value for flags is SE_UID which returns the UID of the message rather then the message ID.


This list may not be accurate due to client implementations. For a canonical list, see section 6.4.4 of RFC2060


Since versions 3.0.12 and 4.0

See also

See also: imap_scanmailbox


Example 619. Search for all messages with 'password' in the subject

$imap = imap_open("{localhost}INBOX","graeme","inferno");

// search only in the subvject for the string 'password'
$boxes = imap_search($imap, "SUBJECT password");
for ($i=0; $i<count($boxes); $i++) {
   echo "Match found in number: $boxes[$i]<BR>\n";

// search again but return the UID
$boxes = imap_search($imap, "SUBJECT password", SE_UID);
for ($i=0; $i<count($boxes); $i++) {
   echo "Match found in UID: $boxes[$i]<BR>\n";


Match found in number: 2
Message found in UID: 8

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.