开发者

How to read email attachment

What I have:

A person da开发者_开发技巧ily 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.: xmls@mywebsite.com 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜