使用 PHP 将入站电子邮件附件保存到磁盘
我正在寻找编写一个 PHP 脚本,我也可以通过管道发送电子邮件。然后,该脚本提取所有附件并将它们保存到服务器上的文件夹中,并丢弃该消息。
我发现了许多将电子邮件作为可以拆分的字符串来读取的示例:
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
但是,这些示例都不能处理 mime 附件的提取。我看过 PHP 手册 但没有运气了解如何将它们组合在一起。
有没有一种简单的方法可以做到这一点,甚至可以使用管道而不是流行帐户?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与您如何处理消息本身的结构无关。为了回答如何同步读取消息而不是轮询的问题,我们需要知道它所在的操作系统以及 MDA 是如何配置的(提示:如果是 Unix/Linux/POSIX,请使用 procmail)。
关于如何削减电子邮件正文的描述远远超出了此处的答案 - 但您可以在互联网上找到许多现成的解决方案。例如 这个
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