1

I am currently working on a bespoke system where i need to loop through an IMAP email account where the emails im looking for need lay within a date range.

As it stands, i have a working IMAP search function which is getting all emails with a certain string in the subject, the part which i cannot seem to find any documentation for, is the BETWEEN date range. I have seen that you can use the BEFORE ON & SINCE criteria but this doesn't seem to allow me to create a range as such.

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to mailbox: ' . imap_last_error());
$emails = imap_search($inbox,'SUBJECT "Undelivered Mail Returned to Sender" ON "'.$date.'"');

Im not asking for a complete spoonfeed but a point in the right direction would be appreciated.

Thanks a lot, Lewis

1 Answer 1

10

For those interested: After staring at the documentation for imap_search for about 10 minutes, i decided to try using both SINCE and BEFORE together. I managed to get the following code to do exactly what was required.

$emails = imap_search($inbox,'SUBJECT "Undelivered Mail Returned to Sender" SINCE "'.$dateMonth.'" BEFORE "'.$date.'"');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.