I need to retrieve bounced email using a web app in PHP.
I need to find all emails return message starting from an email sent by the web app.
For example with an email sent (and saved into my DB with ID = 1): I want to show all message response linked to this email.
I tried using imap_search
with options SUBJECT "my original subject"
but it doesn't work all times! FOr example, gmail for bounced response, replace original subject into "Delivery Status Notification (Failure)
"
So i'd like to do the search using others possible options. I see exist an option called KEYWORD
but i don't find example and appropriate documentation how to use it.
I'd like to semplify my job for example inserting a unique indentifier into the header of my email sent, so I can search into INBOX responses using this identifier.
What you want to do is a little difficult. A few days' programming.
The kind of message you're looking at is called a DSN, or delivery status notification. It's not a response. It is related to the original message, but its relationship is a different kind, it's not a reply. (Forwarded messages are also not replies.)
You'll have to actually parse the message/delivery-status part in DSN to find out which bounces relate to which messages. (It's even more difficult for forwarded messages, but perhaps you don't have that problem.)
The keyword keyword is for message flags, such as \seen
.