简体   繁体   中英

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

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 server, 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. eg this one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM