How to search mails from mailbox using Subject lin

2019-05-29 21:22发布

问题:

I am using IMAP to read a mailbox.

Now is it possible that I can search mailbox with SUBJECT LINE and FROM name as flag ?

Example: is it possible to define search criteria : imap_search($login,'SUBJECT '.$sub.' FROM'.$ToSearch); Is it allowed to use from name and subject in search for an email ?

回答1:

See the SEARCH Command section of RFC 3501 to see how to use search functionality in IMAP. An AND operation is implicit so you can just put conditions next to each other:

0001 SEARCH SUBJECT "hello world" FROM "john"

If you want an OR operation instead, you need to prefix the criteria with the OR keyword:

0002 SEARCH OR SUBJECT "hello world" FROM "john"

Note that strings are used as substring search, i.e. the FROM in these cases will match both "john" and "john@malta.com".



标签: php imap