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



我正在开发我的PHP以将电子邮件存储在已发送的文件夹中。我在电子邮件中存储 url 时遇到了问题,因为当应该id=msgid=时,我将在 img 标签 src 中idmsgid。我已经研究了几个小时,但我无法找到如何在 html 中存储=,因为我不断收到以及何时将电子邮件存储在发送的文件夹中。

当我尝试这个时:

<?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."rn".
"To: ".$to_email."rn".
"Subject: ".$subject."rn".
"Date: ".date("r", strtotime("now"))."rn".
"Message-ID: ".$messageID."rn".
"MIME-Version: 1 rn".
"Content-Type: multipart/mixed; boundary="$boundary1"rn".
"rnrn".
"--$boundary1rn".
"Content-Type: multipart/alternative; boundary="$boundary2"rn".
"rnrn".
// ADD Plain text data
"--$boundary2rn".
"Content-Type: text/plain; charset="utf-8"rn".
"Content-Transfer-Encoding: quoted-printablern".
"rnrn".
$message."rn".
"rnrn".
// ADD Html content
"--$boundary2rn".
"Content-Type: text/html; charset="utf-8"rn".
"Content-Transfer-Encoding: quoted-printable rn".
"rnrn".
$message."rn".
"rnrn".
"--$boundary1rn".
"rnrn".
// ADD attachment(s)
$attachment1.
"rnrn".
"--$boundary1--rnrn",
"\Seen"
);

以下是它将在 id 旁边和msgid 旁边显示的内容,如下所示:

<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 标签 url 中具有CC_10和CC_11而不显示时,我应该使用什么来将 html 电子邮件存储在已发送的文件夹中

?谢谢。

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

试试这样的事情

$message= nl2br($message);

最新更新