I need to programmatically capture emails as well as any files that are attached to them using php. Also is running a cron job the only way to continue checking if there are any new emails or is there a way to automatically fire some code as a new email arrives? Thanks any help is appreciated!
Share
To the second part of your question: If you run your own mail server and want to avoid polling to fetch new messages, then you can add an entry to /etc/aliases that lets your MTA know to forward to your PHP script, like so:
uploads: "|/usr/bin/php -q /var/flickr/uploads.php"This entry will tell your MTA to pipe any emails for
uploads@example.comtouploads.php. From there, you can readSTDIN, parse the MIME message, and processes it as you please(stolen from Cal Henderson’s Book Building Scalable Websites. I highly recommend Chapter 6)