dongzhi1851 2017-12-05 03:33
浏览 14

使用PHP保存电子邮件中的文件

I'm writing a fetcher of emails from IMAP. I've written my code so that it will look for BOTH attachments and inline images.

Everything works great, but I'm having trouble with the file_put_contents part where the content of the attachment is saved.

I've just put $object['attachment'] as kind of a best guess around what it should be, because I don't know how to obtain this from the array/s.

$inbox = imap_open($hostname,$username,$password);

$emails = imap_search($inbox,'ALL');

if ($emails) {

  rsort($emails);

  foreach($emails as $n)  {

    $structure = imap_fetchstructure($inbox,$n);

    foreach($structure->parts AS $object) {

      if (strtolower($object->disposition) == "attachment") {

        foreach ($object->dparameters AS $object2) {
          if(strtolower($object2->attribute) == "filename")
            $filename = $object2->value;
        }
        //file_put_contents($filename, base64_decode($object['attachment']));
      }

      foreach($object->parts AS $object2) {
        if (strtolower($object2->disposition) == "inline") {

          foreach ($object2->dparameters AS $object3) {
            if(strtolower($object3->attribute) == "filename")
              $filename = $object3->value;
          }
          //file_put_contents($filename, base64_decode($object['attachment']));
        }
      }

    }
  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭