我正在使用PHP-imap来阅读来自 IMAP 帐户的电子邮件和附件。这些电子邮件是从 iPhone 或 iPad 发送的。当他们写一封电子邮件并粘贴到他们拍摄的图像中时,它工作得很好。
这是我如何获取附件的片段:
require_once("plugins/MailLib/MailLib.php");
$mailbox = new MailLib();
$mailbox->connect($username, $password, $server, $port, $path, false);
$mails = array();
$mailIds = $mailbox->getMails("UNSEEN");
if($mailIds != null && count($mailIds) > 0) {
foreach($mailIds as $mailId) {
$mail = $mailbox->getMail($mailId);
if($mail['attachments']) {
foreach($mail['attachments'] as $attachment) {
$file = $mailbox->getAttachment($attachment, $mailId);
$destFile = "path/to/folder/".time().".jpg";
$fh = fopen($destFile, 'a') or die("can't open file");
fwrite($fh, $file);
fclose($fh);
}
}
}
一旦他们开始使用默认选项(如粗体、斜体或下划线)格式化内容,一切都会崩溃。因为那时我收到以下电子邮件内容:
<div>
<em>Test</em> with <strong>formatting</strong>
<br>
<br>
<img id="7CB777EB-3124-4AEA-8894-6F743EA78F79" src="cid:7CB777EB-3124-4AEA-8894-6F743EA78F79" alt="image.jpeg">
<br>
<br>
<div>Send from my iPhone</div>
</div>
是否有任何类型的 php 库也可以获取这些附件?