如何将电子邮件正文中的 html 源代码转换为有效的 html?

问题描述 投票:0回答:1

我正在使用 php 脚本自动从 IMAP 服务器下载电子邮件。电子邮件正文的 HTML 看起来像这样:

<!DOCTYPE html><html lang=3D"en" xmlns=3D"http://www.w3.org/1999/xhtml" xml=
ns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-microsoft-com=
:office:office"><head><meta http-equiv=3D"Content-Type" content=3D"text/htm=
l; charset=3Dutf-8"><meta name=3D"viewport" content=3D"width=3Ddevice-width=
,initial-scale=3D1"><meta http-equiv=3D"X-UA-Compatible" content=3D"IE=3Ded=
ge"><meta name=3D"x-apple-disable-message-reformatting"><meta name=3D"forma=

对我来说,除了末尾带有“=”的换行符之外,这看起来都像正确的 html,但我不能 100% 确定 html 在电子邮件中存储的方式是否没有其他内容发生更改。

在需要时删除行尾的“=”以及在电子邮件正文中存储 html 时发生的其他潜在更改(最好是在 PHP 或 Linux 命令行中)的最佳方法是什么?我想最终将其保存为 HTML 文件,以便可以在浏览器中查看它或从该格式转换为其他格式。

谢谢!

php html mime
1个回答
0
投票

电子邮件中使用的格式称为“引用可打印”。转换它的 php 函数是 quoted_printable_decode()

解决此问题的示例函数是:

$decoded_data = quoted_printable_decode($text);
© www.soinside.com 2019 - 2024. All rights reserved.