I’m looking for a way to capture and manage email data using PHP. Basically, what I want to do is capture all the data in an email and then manipulate this data to my specification.
For example, say, I send an email containing a .zip file attachment to myemail@myproject.com, I want to be able to:
- Get the attachment and place it in a specific folder on my site
- Get the text content of the email
- Get the subject of the email
- Get the sender’s info i.e. email address
Anyone know how I can get this done efficiently with PHP. I’m using LAMP by the way.
Thanks.
Start with PEAR
Mail_mimeDecode. What you are looking to do is ambitious but can be done.Basically what you will be doing is:
Instructing your MTA to deliver mail from an address to a pipe into your PHP script. Postfix and Sendmail can handle this with an alias like:
Your PHP script will likely read the email message from STDIN and then pass the string to
mimeDecode, which creates an object containing all the MIME parts.Assuming your message was received into
$strfrom STDIN, something like this gets you started: