我希望我的电子邮件正确显示图片。
我设法通过以下方式提取电子邮件:
$hostname = '{mail.domain.com:143/imap/novalidate-cert}INBOX';
$username = "*****";
$password = "*****";
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect : ' .
imap_last_error());
$message = imap_fetchbody($inbox, 4, 1.2);
结果显示除图像外的所有内容。 图像显示scr =“cid:profilephoto”,这意味着它指向同一页面上的某个嵌入图像,但由于imap_fetchbody只显示消息体的某个部分,所以我无法分辨出图像的位置。
<img src="cid:profilephoto" width="27" height="27">
当我将imap_fetchbody数设置为2时:
$message = imap_fetchbody($inbox, 4, 2);
然后它显示图像部分,但只显示base64编码图像而不是其他HTML。
iVBORw0KGgoAAAANSUhEUgAAAHQAAAApCAMAAADTVP08AAAC6FBMVEUAAAAPY+IVZ+QOYN0PZ+cV auvPNycPX98PZOkPY+fURjPSPCn/swD/rwAabObfTz8Taesdce8PZOX0qwD/tQDcUj8Taev/rwDJ OSb/rwAVauwPZecPZOUPZOTUPyrGNyXPPy/YQi8bb+vxrQD/vBXRQCrPOyfXRS/PLx8ab+/XRzHf VUEfb+8TZuIAj0fMNyfWQivVQSwOY+QUZeD/tQEZb+0Aj0UUauvRPSf/tAAZb+3ZRTEQYuD/vw/E NyUPZuUUa+zJNSX/tQETZ+YcbekGol/MPisGoFzPPirVUD7XQy8UZuEAj0oab+/ROygVZ+ISaOr5 twjNOSfgV0UZaeP/vA3VUD7bUj7YSDTfTz//uQ/aRjHxthMRYt0ece//wBXfUT8ccu8fbePZTzoJ pWEHn18Aj0v/tgDLPSgAjUr/tgQAj0sQYdwAj08AkU0PY+P/twv5rwD0tRf/uQv/uBP/vRQNXtnX Tzv/uQUTZN/ZTDrXRy//swD0tAPaTjrQPCfeVUPgVEL5vRPNOifcVELXRzPcSzj/sgATZugWbOsh cu8XbO4Wa+wab+8QZObWQSsSZ+kUaevYQi3/swAVauwRZ+gYbe4gc/Adce8ecvAcce8TaerTPirU PyrRPSnbRTEAnlkAkUzZRC8QZecRZujZSjU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5P05CYmIZ DbAq3cYqQOLWhBHlnPUe0AMqKtKdU7q7JwTK4b8jDy3TECWirqZhylNjCVPAhdBjNJrQzykM1pKb u5oC14MTcI0W/NX4tYgAl0NmXS4+VRuy3MHlRKjVZSAyNyuvDlwOfgpn9bzQ3PtBajAYKDGQZmYm gMuR4IhHdHvMVErB5cjzkEA+oCKVyijoByIzkbpAOZJQ1z9OJLCOaJUc7jS4HPEarUOhJPBfj/Nv 9fJre47yRD8AAAAASUVORK5CYII
如何将此元素的嵌入图像设置为指向?
请不要使用PHPmailer或Swiftmailer库或任何其他库。
答案 0 :(得分:0)
我解决了自己的问题。
function mime($x,$y,$z){
$a=array();
$b='Content-';
$c=explode($b,trim(str_replace(array('<','>'),"",(imap_fetchmime($x,$y,$z,FT_UID|FT_PEEK))),$b));
if($c!=""){
for($n=0;$n<count($c);$n++){
if($c[$n]!=""){
$d=explode(':',$c[$n]);
$a[strtolower($d[0])]=$d[1];
}
}
}
return $a;
}
上面的功能帮助我:
如何使用它?
$set=mime($inbox,4,1); // Connection, msgid, part/body section
输出参考:
$set['type'];
$set['disposition'];
$set['transfer-encoding'];
$set['id'];
使用$ set ['id']给出的引用ID,您可以在消息体中搜索src =“cid:[id]”并使用base64图像更改src值。