简体   繁体   English

PHP脚本管道电子邮件解析

[英]PHP script piping email parse

I'm doing this piping php script that fetch the arriving emails and the parse it and show it. 我正在做这个管道php脚本,该脚本获取到达的电子邮件并对其进行解析并显示出来。 I used this tutorial: http://www.damnsemicolon.com/php/parse-emails-in-php-with-email-piping-part-1 (and the following ones), I tried it with a standard email that I had sent to my server and it did work well, but then i tried another and I got a lot of errors. 我使用了本教程: http : //www.damnsemicolon.com/php/parse-emails-in-php-with-email-piping-part-1 (及以下),我尝试使用标准电子邮件已发送到我的服务器,并且运行良好,但是后来我尝试了另一个,但出现很多错误。 I used the print_r($decoded); 我用了print_r($ decoded); to show me all of the different parts of the email and instead of getting a fully parse email, all the content of the emails goes to the $decode[0]['body]; 向我展示电子邮件的所有不同部分,而不是获得完全解析的电子邮件,电子邮件的所有内容都转到$ decode [0] ['body]; Why is this happening? 为什么会这样呢? (I will not post the code cause it's the same as the tutorials) (我不会发布代码,因为它与教程相同)

print_r($decode)= Array (
    [0] => Array ( 
         [Headers] => Array ( ) 
         [Parts] => Array ( ) 
         [Position] => 0 
         [Body] => From jtferreira@teste.local Thu Apr 26 12:33:44 2012 Received: from [192.168.1.92] by ubuntuserver.lan with esmtp (Exim 4.76) (envelope-from ) id 1SNMxE-0000VB-TR for jtferreira@teste.local; Thu, 26 Apr 2012 12:33:44 +0100 Message-ID: <4F993299.8040605@teste.local> Date: Thu, 26 Apr 2012 12:33:45 +0100 From: =?ISO-8859-1?Q?=22Jo=E3o_Ferreira_=28m=E1quina_virtual=29=22?= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: jtferreira@teste.local Subject: Sample Email Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit It's the same? 
         [BodyPart] => 1 
         [BodyLength] => 744 
     )
 )

Thanks. 谢谢。

As Mario said, the problem was with the UTF 8-BOM. 正如Mario所说,问题出在UTF 8-BOM。 If anyone have this problem, I recomend you to use this code: 如果有人遇到此问题,建议您使用以下代码:

<?php
// substitua pelo caminho para o arquivo que deseja limpar
$file = "C:/wamp/www/wordpress/wp-content/themes/basic-gray/lib/langs.php";
print removeUTF8BOM($file) ? 'BOM removido!' : 'Não havia BOM a ser removido...';

function removeUTF8BOM($fil) {
$newcontent = '';
$first = false;
$fh = fopen($fil, 'r');
  while($part = fread($fh, 1024)) {
    if(!$first) {
      if(preg_match('/^\xEF\xBB\xBF/', $part)) {
      $newcontent = preg_replace('/^\xEF\xBB\xBF/', "", $part);
      } else {
      fclose($fh);
      return false;
      }
    $first = true;
    } else $newcontent .= $part;
  }
fclose($fh);
$fh = fopen($fil, 'w');
fwrite($fh, $newcontent);
fclose($fh);
return true;
}
?>

(http://www.caugb.com.br/2009/07/remover-o-bom-de-arquivos-em-utf-8/) (http://www.caugb.com.br/2009/07/remover-o-bom-de-arquivos-em-utf-8/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM