开发者

Using PHP to save an inbound e-mail attachments to disk

开发者 https://www.devze.com 2023-02-12 20:34 出处:网络
I am looking to write a PHP script that I can pipe an email too. The script then extracts all attachments and saves them to a folder on the se开发者_StackOverflow社区rver, discarding the message.

I am looking to write a PHP script that I can pipe an email too. The script then extracts all attachments and saves them to a folder on the se开发者_StackOverflow社区rver, discarding the message.

I have found many examples to read the email as a string which can be split up:

$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

However non of these handle the extraction of mime attachments. I have had a look at the PHP Manual but with no luck on seeing how to slot it all together.

Is there an easy way to do this, it is even possible using pipes rather than a pop account?


it is even possible using pipes rather than a pop account?

That's got nothing to do with how you handle the structure of the message itself. To answer the question of how to read the message sybchronously instead of polling, we'd need to know what OS this is on and how the MDA is configured (hint: if its Unix/Linux/POSIX, use procmail).

A description of how you go about paring the body of the email goes way beyond an answer here - but you can find lots of ready made solution on the internet. e.g. this one

0

精彩评论

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