0

Gmail のメールを取得して Web ページにエコーするための PHP コードを次に示します。

<?php


                            /* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'username@gmail.com';
$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--**
4

1 に答える 1

1

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

これは、これと同様に、それを解析して正しく処理するのに役立つ場合があります

于 2011-12-07T17:25:35.640 に答える