我已经设法使用IMAP php库显示我的电子邮件,而不使用任何额外的框架。我遇到的唯一问题是无法获得嵌入的图像。我可以用imap_fetchstrucure看到我的电子邮件结构,我的图像在中
[1] => stdClass Object
(
[type] => 5
[encoding] => 3
[ifsubtype] => 1
[subtype] => JPEG
[ifdescription] => 0
[ifid] => 1
[id] => <image002.jpg@01CE9203.CFB44C60>
[bytes] => 2668
[ifdisposition] => 0
[ifdparameters] => 0
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => name
[value] => image002.jpg
) )
image002.jpg@01CE9203.CFB44C60,如何从Gmail获取/显示此图像?有没有现成的URL来获取图片www.gmail.com/image002.jpg?
经过搜索和研究,找到了解决方案,我不会详细了解如何阅读正文,但在这个例子中,我在第4封电子邮件和第3部分中嵌入了.jpg图像:
<?php
$mbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
$message=imap_fetchbody($mbox, 4,3);
$decoded_data = base64_decode($message);
file_put_contents('image002.jpg',$decoded_data);
?>
<img src="image002.jpg">
<?php
你必须先保存它,然后才能显示它。找不到直接显示它的方法。