私はgmail用の基本的な読み取り専用クライアントをまとめています。imap(PHP)を介してメールを正常に取得し、保存していますが、ブラウザに表示する際にいくつかの問題が発生しています。
ほとんどの電子メールは完全な html ページ<html><title>Your Mail</title><body>etc...</body></html>であり、電子メールが表示されているルート html ページが破損することがよくあります。
たとえば、多くの場合、
<html>
<title>Read only mail>
<body>
<h1>Your mail:</h1>
<html><title>An email from steve</title><style>html {background-color=red;}</style>
<body>It's a read email! (get it?)</body></html>
<html><title>An email from james</title><style>body {background-color=green;}</style>
<body>I like green things, save the planet!</body></html>
More mail etc...
</body>
</html>
これは完全に有効な html ではありませんが、主な問題は、メールの CSS がページ上の他のすべての要素に影響を与えることです。私の最善の考えは、何らかの方法で PHP で iframe を作成することです (これは、追加の要求なしで可能ですか)。ドキュメントのすべての CSS と HTML。
この問題を回避する方法を知っている人はいますか? gmail やその他の Web クライアントはどのようにそれを行いますか? Javascript/jQuery & Ajax などのクライアント側のソリューションを検討していただければ幸いです
御時間ありがとうございます、
--
現在、メールは次のように出力されます。
/* connect */
$inbox = imap_open($hostname,$username,$password) or die(imap_last_error());
$emails = imap_search($inbox,'ALL');
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,2);
    /* output the email header information */
    $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
    $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
    $output.= '<span class="from">'.$overview[0]->from.'</span>';
    $output.= '<span class="date">on '.$overview[0]->date.'</span>';
    $output.= '</div>';
    /* output the email body */
    $output.= '<div class="body">'.$message.'</div>';
  }
  echo $output;
} 
/* close the connection */
imap_close($inbox)
http://davidwalsh.name/gmail-php-imapから取得 (私のコードは若干異なりますが、デザインと出力は同じです)