PHP quoted_printable_decode无法处理Fandango普通/文本电子邮件

时间:2013-07-07 22:45:48

标签: php email quoted-printable

我正在努力清理电子邮件,然后才将其存储在数据库中。 fandango电子邮件被编码为4(引用可打印)。这是消息的一部分,没有解码...

  

= 0A = 0A = A0 = 0AJohn = 0A(800)123-4567 = 0A = 0A -----转发消息=

     

= 20 = 0ASent:= 20Thursday,= 20July = 204 = 202013 = 204:14 = 20PM = 0ASubject:= 20Your = 20Despicab =

     

勒= 20Me = 202 = 20iTunes = 20Download = 0A = 20 = 0A 0A = = = 0ADespicable = 20Me 202 = 20 = 0A = 20 = 20 = 0A = 20Your = 20purchase = 20 =

     

of = 20tickets = 20for = 20Despicable = 20Me = 202 = 20has = 20earned = 20you = 20a = 20complimentary = 20download = 20of = 20t =

he = 20song = 20 '只要= 20A = 20Cloud = 20Away'= 20by = 20Pharrell = 20from =第二十条= 20Original = 20Motion = 20Picture = 20So =

     

undtrack = 20on = 20iTunes。= 20 = 0AWe = 20hope = 20you = 20enjoy =第二十条= 20song = 20于是=第二十条= 20film!= 0AIf = 20you =20公顷=

     

VE = 20iTunes = 20installed,= 20click = 20here = 20to = 20start = 20your = 20complimentary = 20download。= 0AIF = 20 =

     

您= 20DO = 20NOT = 20HAVE = 20iTunes = 20INSTALLED:= 0A = 0A1 = 20Download = 20iTunes = 20for = 20Mac = 20or = 20Window =

     

S,= 20free = 20of = 20charge = 20AT = 20www.iTunes.com。= 20 = 0A2。= 20Open = 20iTunes = 20于是= 20click = 20iTunes = 20Sto =

     

重。= 20 = 0A3。= 20Click = 20Redeem = 20under = 20Quick = 20个站点。= 20 = 0A4。= 20Enter =第二十条= 20code = 20below。= 20Your = 20 =

download = 20will = 20start = 20immediately。= 20Enjoy。= 20 = 0ADownload = 20Code:= 20FML6H34XXTMJ = 20 = 0AC =

但是当我在变量上使用quoted_printable_decode()时,它不会产生任何文本。


这个网址有一个解码器可以工作,虽然在ASP / VB ...

http://www.motobit.com/util/quoted-printable-decoder.asp

我猜这里的代码是相关的......

http://www.motobit.com/tips/detpg_quoted-printable-decode/

它正确地解码了以上引用可打印的HTML。希望这会帮助有人试图帮助我。我敢肯定,我不是唯一一个遇到破损的报价可打印电子邮件的人。

2 个答案:

答案 0 :(得分:0)

您发布的quoted-printable编码字符串中似乎有一些空格。这可能是导致问题的原因 - 如果它是真正引用的可打印的,那么编码的字符串不应该包含任何空格。引用可用的空格= 20。如果使用替换函数(例如PHP的str_replace)将编码字符串中的空格替换为= 20,则会得到以下带引号的可打印编码字符串:

约翰= 0D 0A =(800)= 20123-4567 = 0D 0A = 0D = 0A = ----- = 20Forwarded = 20Message = 20

然后,可以使用PHP的quoted_printable_decode()函数解码此字符串。

答案 1 :(得分:0)

如果将上面引用的可打印编码文本复制到文件中,则运行以下PHP脚本(从文件中读取引用的可打印文本,使用str_replace函数删除空格,然后解码引用的 - 使用quoted_printable_decode函数打印文本,您应该看到它生成正确的解码输出:

 <?
 $filename="./qp.txt";
 $file = fopen($filename,"r");
 $qp = fread($file,filesize($filename));
 fclose($file);

 $qp=str_replace(" ", "", $qp);
 print "<plaintext>";    
 print quoted_printable_decode($qp);
 ?>