如何在php中保存电子邮件的附件? [英] How to save the attachments of a email in php?

查看:127
本文介绍了如何在php中保存电子邮件的附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检索电子邮件,然后解析到数据库中.

I am retrieving the emails and then parsing into the database.

但是问题是我能够检索电子邮件,但附件部分也显示在浏览器中.我需要将此附件部分保存到某个位置.附件的格式为纯文本/纯文本.

But the problem is i am able to retrieve the email but the attachment part is also shown on the browser.I need to save this attachment part to the some location .The format of attachment is text/plain.

这是我的代码

<?php
    $inbox=imap_open("{xyz.com:995/pop3/ssl/novalidate-cert}INBOX", "username", "password");
    $count = imap_num_msg($inbox);

    for($i = 1; $i <= 1; $i++) {
     $raw_body = imap_body($inbox, $i);
     echo $raw_body;
     imap_delete($inbox, 1);
    }
    imap_expunge ($inbox);
?>

我在这里检索了电子邮件

here i have retrievd a email

但是我不知道如何保存附件. 当我使用imap_body时,附件也显示在电子邮件的下方.

But i dont know how to save the attachment . The attachment is also shown below the body of the email when i am using the imap_body.

所以我应该如何将这两个分开.

So how should i separate these two..

推荐答案

通过使用 imap_fetchstructure(),您可以获得有关邮件不同部分的列表.使用 imap_fetchstructure(),您实际上可以将有趣的部分你.请查看后面的文档中注释中的示例代码.

by analysing the mail with imap_fetchstructure() you can get a list to the different parts of the mail. With a imap_fetchstructure(), you actually take the parts interesting to you. Have a look at the latter documentation for an example code in the comments.

这篇关于如何在php中保存电子邮件的附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆