views:

53

answers:

2

What I have:

A person daily sends to me an email, which has a zip'ed XML attachment.

What I do:

I save that attachment, unpack it and import via XML importerer to my web site.

What I need:

Automatic script, what I can automatically forward my email to ex.: [email protected] and read that attachment via some php file in my website, which maybe will be activated daily via server cronjob.


Is it possible to code this?

And maybe someone has any pre-coded scripts.

Thanks for answers.

A: 

This can be done using the ZZIPlib library

I have implemented the following post with good results.

http://www.timlinden.com/blog/website-development/unzip-files-with-php/

Hope this points you in the right direction.

phill
+1  A: 

If you're on a Unix host and the mail is (or can be) sent to a local account on that machine, you can forward the email directly to your PHP script without needing to access a mail account directly.

You can do this in /etc/aliases:

 nameofaccount: "|/path/to/your/script.php"

or in the account's ~/.forward file:

 "|/path/to/your/script.php"

As long as you set the script up to be treated as a shell script (chmod 755, with appropriate #!/usr/bin/php shebang at the start), the script will be executed each time an email comes in and you can (I believe) retrieve the full email's text from the php://input or php://stdin stream.

After that it's just a matter of seperating out the attachment and processing that.

Marc B