As already mentioned, checking mailbox (POP3 or IMAP) is a valid way to handle email. However, if you are looking for real-time processing, it is really possible that mail is delivered directly to php as standard input.
Basically you tell the mail server to deliver the message to a local script.
You will need to delve into the CLI PHP and set up your mail server (which should be on the same server as when processing the script). So this is not an easy process. But it is possible. Using this method, I am currently running a discussion list via email based on PHP.
I set up my old time, so I canβt remember all the details; but this article should point you in the right direction.
source share