You need to look into email piping and using PHP stdin, etc. I am sure looking for "email piping php" in google will turn up some results. Essentially you will be piping email that comes in on an email address,
name@example.com, to a PHP script that accepts input via stdin (again, just search google... I am sure there are many examples available). Thus, you will need to both configure the email address to pipe to the PHP script and create the PHP script that will be able to handle the email data. Enabling email piping can vary, so just ask your host for help in that matter.
As for checking directory contents:
Take a look at
readdir() function.