如何在PHP中使用imap从电子邮件中提取嵌入式图像(而非附件) [英] How to extract inline images(not attachment) from an email using imap in PHP

查看:175
本文介绍了如何在PHP中使用imap从电子邮件中提取嵌入式图像(而非附件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在php中使用imap获取电子邮件时,我收到了电子邮件正文内容,但是无法提取粘贴的并且未附加到电子邮件正文中的嵌入式图像.

When i fetch email using imap in php, i get email body content but i m not able to extract inline images pasted and not attached in the email body.

推荐答案

嘿,我想我有解决办法

hey i think i got a solution

<?php
   $hostname = '{myserver/pop3/novalidate-cert}INBOX';
   $username = 'username';
   $password = 'password';

   /* try to connect */
   $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error());
   $msgno = 0; //message id
   $no_of_occurences = 0;
   $intStatic = 2;//to initialize the mail body section

   $decode = imap_fetchbody($mbox, $msgno , "");    
   $no_of_occurences = substr_count($decode,"Content-Transfer-Encoding: base64");//to get the no of images
   if($no_of_occurences > 0){
        for($i = 0; $i < $no_of_occurences; $i++){  
             $strChange =   strval($intStatic+$i);
             $decode = imap_fetchbody($mbox, $msgno , $strChange);//to get the base64 encoded string for the image
             $data = base64_decode($decode);
             $fName = time()."_".$strChange . '.gif';
             $file = $fName;
             $success = file_put_contents($file, $data);        //creates the physical image    
        }           
    }
    imap_close($inbox);
 ?>

这篇关于如何在PHP中使用imap从电子邮件中提取嵌入式图像(而非附件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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