2016-05-11 15 views
1

PHP経由でHTML電子メールを送信するコードがあります。それはテーブルを持っています。私はスクリーンショットで丸めて大胆にしたい。しかし、Gmailに到着した電子メールは、大胆に表示されず、「約」のクラスセレクタに適用されるべき他の変更も表示されません。PHP HTML電子メールクラスセレクタが動作しないGMAIL

received email screenshot

私は、PHP、HTMLメールに自分のスタイルシートでクラスまたはIDセレクタを使用することはできますか?非効率であるため、私はインラインCSSを使いたくありません。私は体の中でそれらを使用しました。 ここにコードがあります。

$to = "[email protected], [email protected]"; //multiple recipients with comma separated 
$subject = "Here is the subject"; //cannot contain newline characters 

$message = "<h1>This is Heading H1</h1>"; 
$message .= "This is my <b>first</b> line of text.<br>This is my <b>second</b> line of text<br><br>"; //each line should be separated with (\n). 
$message .= "<html> 
       <head> 
        <style> 
         body{ 
          color:#000000; 
          background-color:#FFFFFF; 
          font-family:arial, verdana, sans-serif; 
         } 
         h1{ 
          font-size:18px; 
         } 
         p{ 
          font-size:12px; 
         } 
         table{ 
          background-color:#efefef; 
          border-style:solid; 
          border-width:1px; 
          border-color:#999999; 
         } 
         th{ 
          background-color:#cccccc; 
          font-weight:bold; 
          padding:5px; 
         } 
         td{ 
          padding:5px; 
         } 
         td.about{ 
          font-family:courier, courier-new, serif; 
          font-weight:bold; 
         } 
        </style> 
       </head> 
       <body> 
        <table> 
         <tr> 
          <th> About </th> 
          <th> Description </th> 
         </tr> 
         <tr> 
          <td class=\"about\"> Name </td> 
          <td> Andreas </td> 
         </tr> 
         <tr> 
          <td class=\"about\"> Address </td> 
          <td> Germany </td> 
         </tr> 
         <tr> 
          <td class=\"about\"> Message </td> 
          <td> I like your 8 day tour package. What are the rates? </td> 
         </tr> 
        </table> 
       </body> 
      </html> 
      "; 

//headers like From, Cc, Bcc, Reply-to, Date ??????????? 
//$header = "From:[email protected] \r\n"; 
$header = "From: RXXXXX CXXXXX <[email protected]> \r\n"; //additional headers should be separated with (\r\n) 
//$header .= "Cc: [email protected] \r\n"; 
//$header .= "Bcc: [email protected] \r\n"; 

//always specify MIME version, content type, and character set when sending HTML email 
$header .= "MIME-Version: 1.0 \r\n"; 
$header .= "Content-type:text/html;charset=UTF-8 \r\n"; 
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //////////////////////////////Pls Delete later 

$retval = mail($to, $subject, $message, $header); 

if($retval == true){ 
    echo "Message sent successfully"; 
} 
else{ 
    echo "Message could not be sent!"; 
} 
+0

あなたのCSSで '.about {...'のみを試しましたか? –

+0

@PedroLobito先生、これらすべてのバリエーションを確認しました:.ab {...、td.ab {...。しかしgmailはクラス名を特定しません。しかし、Yahooは正しく表示されます –

+4

簡単な答えは、HTML電子メールの場合、異なる電子メールクライアント間で一貫性を得るためにCSSをインライン化する必要があることです。 HTML電子メールは、各電子メールクライアントが異なる方法でCSSと書式をレンダリングするため、悪名を抱いています。 –

答えて

0

HTMLのメールは正しく取得するのが難しいと知られています。各電子メールクライアントは異なる方法でスタイリングを処理します。リー・マンローのThings I've Learned About Building & Coding HTML Email Templates(強調は著者のである)からの引用:

メールクライアントがHTMLメールをレンダリングするために異なるレンダリングエンジンを使用します。

  • Apple Mailの、Mac用の展望、AndroidのメールとiOSのメールは、WebKitのを使用
  • 見通し2000年2月3日には、Internet Explorer
  • 見通し2007年10月13日は、Microsoft Wordが(はい、ワード!)
  • Webクライアントは、ブラウザのそれぞれのエンジンなどを使用して使用して使用しますSafariはChromeが点滅

Gmailのストリップアウト<link>タグと<style>タグで任意のCSS、およびインライン化されていない他のCSSを使用して、WebKitのを使用しています。 Gmailウェブだけでなく、ネイティブのGmailモバイルアプリも。

あなたの質問に直接答えるために、Gmailは<style>タグをすべて取り除くため、CSSをHTML要素にインライン展開する必要があります。

としてあなたのためのCSSをインライン化することができ、いくつかのWebサービスは、また、あなたがようなCssToInlineStylesとしてライブラリを使用して、それをインライン化することができますがあります純粋にあなたのコード内でそれを処理する。

関連する問題