2 options:
- if GMail accepts your mail, you can't capture it there. If you have a paid account there, you can set up additional routes for specific emailaddresses to also be delivered to a server under your control (in which case Marc B.'s answer should be followed: configure that other mail server to just pipe the mail to whatever script you want).
- if you can't do that, or don't want to, just look at the imap extension of PHP, if plays perfectly nice with Google's IMAP interface in my experience.