2011-12-07 12 views
0

は、GmailのメールをつかんでWebページにそれらをエコーのための私のPHPコードです:php imapは奇妙なヘッダーをエコーし​​ていますが、これを修正できますか?ここ

<?php 


          /* connect to gmail */ 
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; 
$username = '[email protected]'; 
$password = 'password'; 

/* try to connect */ 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 
/* grab emails */ 
$emails = imap_search($inbox,'ALL'); 
/* if emails are returned, cycle through each... */ 
if($emails) { 

/* begin output var */ 
$output = ''; 

/* put the newest emails on top */ 
    rsort($emails); 

    /* for every email... */ 
    foreach($emails as $email_number) { 

    /* get information specific to this email */ 
    $overview = imap_fetch_overview($inbox, $email_number, 0); 
    $message = imap_fetchbody($inbox, $email_number, 1); 



    $DateFormatted = str_replace("-0500", "", $overview[0] -> date); 



    /* output the email header information */ 
    $output .= $overview[0] -> subject ; 
    $output .= $DateFormatted ; 




    //$bodyFormatted = preg_replace("/This e-mail(.*)/","",$message); 
//$bodyFormatted = preg_replace("/Ce courriel(.*)/","",$bodyFormatted); 
    /* output the email body */ 
    $output .= $message; 


          } 

echo $output; 
         } 

         /* close the connection */ 
imap_close($inbox); 

           ?> 

私が午前問題は、私は奇妙なヘッダがメッセージ本文と一緒に口走ったと私はなぜ知らない得続けるということです。ヘッダーの数値部分が毎回異なって生成されるので、str replaceまたはRegexを使用することはできません。これを行うための信頼できる方法が本当に必要です。私はアイデアがなくなり、助けが必要です。 はまた、いくつかのランダムな「=」兆候は

出力行き方:

SiteA Connectivity Issues (resolved)Tue, 6 Dec 2011 13:59:59 **------_=_NextPart_001_01CCB449.406E7C50 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable =20** Please be advised www.siteA.com is no longer experiencing issues. The site is up and fully operational once again. =20 IMPACT: www.siteA.com was experiencing connectivity issues.=20 =20 UPDATE: Connectivity issues have been resolved. Root cause analysis and reporting will be performed tomorrow during business hours. **=20 ------_=_NextPart_001_01CCB449.406E7C50 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable** 



Please be advised www.siteA.com is no longer = experiencing issues. The site is up and fully operational once = again. 



IMPACT: 

www.siteA.com was experiencing connectivity issues. 



UPDATE: 

Connectivity issues have been = resolved. Root cause analysis and reporting will be performed tomorrow during = business hours. 


**------_=_NextPart_001_01CCB449.406E7C50--** 
+0

あなたはMIME境界について話していますか? '------_ = _ NextPart_001_01CCB449.406E7C50-'の部分... – ken

答えて

1

あなたが見ている何のような、彼らはマルチパートメッセージのMIME境界である、ヘッダではありません。メッセージには、HTMLとプレーンテキストの2つの形式の同じデータが含まれています。これはメール本文では非常に一般的です。正しく解析するにはメールのContent-Type:ヘッダーにアクセスする必要があります。 thisを読んでください。

Thisこれを解析して正しく処理するのに役立ちます(thisなど)。

関連する問題