This site runs best with JavaScript enabled.

Download POP3/IMAP Email Attachments with PHP


How to download email attachments via PHP

I found this niftly little class on phpclasses.org. Basically, it logs in to an email server and downloads all email attachments and saves them as files. That's basically it, no more, no less.

This was exactly what I needed though. I wanted to run some daily reports in Google AdWords and Google AdSense, to a specific email address, then process those reports on a daily basis to customize my own reports... in a nutshell.

I did make a few updates to this class.

  1. The $savedirpath variable was not utilized. It simply saved the files in the same location as the script. I had it implement this parameter.
  2. I added another parameter to delete emails after downloading the attachments. Luckily for me, when I went to add the code, I found it was already there, just commented out.
  3. Tidied up the code a bit to make it more readable for me.

You can download the original files here and get my updates here.

Discuss on TwitterEdit post on GitHub

Share article
Dustin Davis

Dustin Davis is a software engineer, people manager, hacker, and entreprenuer. He loves to develop systems and automation. He lives with his wife and five kids in Utah.

Join the Newsletter



Dustin Davis