Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wizjo's avatar
Level 26

How to parse email to application inbox?

Im building application with inner message inbox. From there user can send message which will be sent also as regular e-mail. Now I want to achieve functionality that if receiver will reply that email (from his inbox, outside the website) it will be somehow parsed so I can display it in my application inbox. How to do something like this at all?

0 likes
8 replies
jcmargentina's avatar

I dont quite understand the question ... why you could not just render it with liek a regular view ? maybe I am not getting the architecture right

wizjo's avatar
Level 26

Sorry, probably my language limitations make difficult to explain the idea.

  1. User A sends a message from the portal, which is saved to the database, but at the same time it is sent to the private email address of the recipient-user B.
  2. User B receives a message and responds from his e-mail program to this message, but not to the recipient's private e-mail, but only to the e-mail address of the service.
  3. The site downloads all messages from its mailbox and parses them to save to the database and assign it as a reply to a specific thread and user.

My question is how to achieve this functionality?

I think that:

  1. In step 1 I should send message with reply address with hash, so I can later by that hash assign it to thread and user, for example: [email protected]
  2. Server should be configured to catch that email even if mailbox [email protected] doesnt exist. That could be the problem for me. I don`t know how to achieve that. Maybe all incoming emails should be redirected to one common portal email address?
  3. I can download message by IMAP and using hash in email address assign it to thread and user.

Is it a good solution or maybe it is better way to do that? If it is good I need a prompt in second step- how to configure it like that.

Snapey's avatar
Snapey
Best Answer
Level 122

You need to have the mail arrive in a regular email account and then build pop or imap functionality into your application.

In the past I have reliably used the library php-imap/php-imap

https://packagist.org/packages/php-imap/php-imap

You can open a mailbox, grab the messages and delete them from the mailbox in about 10 lines of code.

Regarding the missing mailboxes, most hosts will allow you to setup a catch-all mailbox that all unknown recipients goes into. You will though expect to get a lot of spam in there so you will probably need something in the body of the email to tell you it is definitely one of yours.

wizjo's avatar
Level 26

I want to do it like that, but how to assign message to specific thread/user?

Snapey's avatar

You can check the headers for who it was to. The Library will do that.

You see helpdesk tickets say "don't change the subject" or a line in the body like

======== Do not remove this @hsys72300dhdjasj ========

which you can easily find with a regex

1 like
wizjo's avatar
Level 26

Ok, this is a solution, but it depends on whether the user actually does not remove something (even accidentally) from the content of the message. Would not such a virtual reply address with hash be a better (more fool-proof) solution? The problem is how to set it?

Snapey's avatar

I've said.

Regarding the missing mailboxes, most hosts will allow you to setup a catch-all mailbox that all unknown recipients goes into.

wizjo's avatar
Level 26

Ok, sorry I missed it somehow. Thank you- that solves my question entirely.

Please or to participate in this conversation.