简体   繁体   English

使用PHP将入站电子邮件附件保存到磁盘

[英]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. 我期待写一个PHP脚本,我可以管的邮件了。 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. 我看过PHP手册,但是运气不好,看不到如何将它们放在一起。

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). 要回答如何同步读取消息而不是轮询消息的问题,我们需要知道它在什么操作系统上以及MDA的配置方式(提示:如果是Unix / Linux / POSIX,请使用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. 关于如何解析电子邮件正文的描述远远超出了此处的答案-但您可以在Internet上找到许多现成的解决方案。 eg this one 例如这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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