For a project I'm working on right now I want users to be able to send e-mails to username@sub.domain.com. Those e-mails or to be more specific ALL e-mails send to sub.domain.com shall be processed by a PHP script.
In that script I need to be able to get the username (the part in front of the @) as well as the e-mail header & body.
Is it possible to do that without previously setting up e-mail aliases for every user?
Is there a way to run the script on e-mail arrival? Or do I have to run a cron job to check periodically? I don't mind if the script is accessible through the web.
From what I've read so far I assume I have to use either IMAP or POP3 for that, is that correct? I have no experience with either of them. Which one is better for this usecase?
Anything else to keep in mind when doing this? Assume I have full control over the server and can change & install whatever is necessary.
Thanks in advance :)
Edit: @Dagon mentioned pipeing the e-mail to a script as an alternative to #3. How? I have never done anything like this before.
Edit2: All I want to do is hook a PHP script to all incoming e-mails. Is that too broad?