PHP IMAP 电子邮件正文解码问题

PHP IMAP email body decode issue

我正在 PHP 将电子邮件存储在已发送文件夹中。我在电子邮件中存储 url 时遇到问题,因为我会在 img 标签 src 中得到 idmsgid,而它应该是 id=msgid=。我已经研究了几个小时,但我无法找到如何将 = 存储在 html 中,因为我一直在获取 </code> 和 <code> 当我将电子邮件存储在已发送文件夹中时。

当我尝试这个时:

<?php
require_once "Mail.php";
require_once "Mail/mime.php";
require_once('Mail/IMAPv2.php');

// Connect to the server:
$username = 'myusername';
$password = '*************';

$sent = '{imap.example.com:993/imap/ssl/novalidate-cert}INBOX.Sent';
$sent_mailbox = imap_open($sent, $username, $password);

$from_email = $_POST['send_from'];
$to_email = $_POST['send_to'];
$subject = $_POST['emailsubject'];
$message = '<div id="emailMessage" class="row" style="padding: 5px 30px;margin-top: 12px;"><div><div dir="ltr"><img src="http://example.com/u/?id=1562453336&amp;attid=0.2&amp;msgid=1644988591229814716&amp;view=attachment&amp;display=view" width="452" height="302" class="CToWUd a6T" tabindex="0"><br><div><br></div><div><br></div><div><img src="http://example.com/u/?id=1562453336&amp;attid=0.1&amp;msgid=1644988591229814716&amp;view=attachment&amp;display=view" class="CToWUd"><br></div><div><br></div><div><br></div><div>



';

$messageID = sprintf("<%s.%s@%s>",
        base_convert(microtime(), 10, 36),
        base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
        'example.com');


imap_append($sent_mailbox, $sent,
    "From: ".$from_email."r\n".
    "To: ".$to_email."\r\n".
    "Subject: ".$subject."\r\n".
    "Date: ".date("r", strtotime("now"))."\r\n".
    "Message-ID: ".$messageID."\r\n".
    "MIME-Version: 1 \r\n".
    "Content-Type: multipart/mixed; boundary=\"$boundary1\"\r\n".
    "\r\n\r\n".
    "--$boundary1\r\n".
    "Content-Type: multipart/alternative; boundary=\"$boundary2\"\r\n".
    "\r\n\r\n".
    // ADD Plain text data
    "--$boundary2\r\n".
    "Content-Type: text/plain; charset=\"utf-8\"\r\n".
    "Content-Transfer-Encoding: quoted-printable\r\n".
    "\r\n\r\n".
    $message."\r\n".
    "\r\n\r\n".
    // ADD Html content
    "--$boundary2\r\n".
    "Content-Type: text/html; charset=\"utf-8\"\r\n".
    "Content-Transfer-Encoding: quoted-printable \r\n".
    "\r\n\r\n".
    $message."\r\n".
    "\r\n\r\n".
    "--$boundary1\r\n".
    "\r\n\r\n".
    // ADD attachment(s)
    $attachment1.
    "\r\n\r\n".
    "--$boundary1--\r\n\r\n",
    "\Seen"
 );

这是它将在 id 旁边显示 </code> 和在 msgid 旁边显示 <code> 的内容,如下所示:

<img src="http://example.com/u/?id62453336&amp;attid=0.2&amp;msgid44988591229814716&amp;view=attachment&amp;display=view" width="452" height="302" class="CToWUd a6T">

我试过这个:

$message = html_entity_decode($message);

我也试过这个:

$message = htmlspecialchars($message);

这没有任何区别,所以我不知道该怎么做。

当我在 img 标签中有 id=msgid= 时,你能告诉我一个例子,我应该用什么来存储发送文件夹中的 html 电子邮件 url 不显示 </code> 和 <code>?

谢谢。

尝试这样的事情

$message= nl2br($message);

如果您使用带引号的可打印文件,则需要转义等号 (=3D)。