If you use IMAP you can use PHP's built-in imap functions. This way, you can access the contents of the email.
Check this site for a tutorial http://davidwalsh.name/gmail-php-imap (It will work on any IMAP account, not just Gmail).
This will help you get up to speed. Then, when you know the basics, follow this tutorial to learn how you can access the attachments through PHP.