2016-02-07 35 views
1

爲什麼不使用mail()php將郵件發送到Gmail時在電子郵件中顯示類css?爲什麼在使用mail()php將郵件發送到Gmail時不能在電子郵件中顯示類css?

我測試這個代碼發送電子郵件到Hotmail它顯示像這樣的電子郵件

enter image description here

但是當我測試這個代碼發送電子郵件到Gmail中它的表現是這樣的。

enter image description here

它沒有表現出類=「按鈕」相同,如Hotmail我該怎麼辦呢?

<?PHP 
include("connect.php"); 
$to  = "[email protected]"; 
$subject = "test email"; 
$message = " 

<html> 
    <head> 
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> 
    <style type='text/css'> 
    .button{ 
     color: #a7a7a2; 
     background: green; 
     padding: 2px 14px; 
     border-radius: 10px; 
    } 
    </style> 
    </head> 
    <body style='margin: 0; padding: 0;font-family: \&quot;Helvetica Neue\&quot;, Helvetica, Arial, sans-serif;'> 
     <table align='center' style='margin:auto;'> 
      <tbody> 
       <tr> 
        <td class='button'> 
         <a href='test.php' target='_blank' style='padding: 11px 0px; display:block; text-decoration:none; color:#000; font-size:16px; text-align:center; font-family:arial; font-weight:bold'>TEST BUTTON</a> 
        </td> 
       </tr> 
      </tbody> 
     </table> 
    </body> 
</html> 

"; 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 
$headers .= 'From: EXAMPLE <[email protected]>' . "\r\n"; 
$headers .= 'Return-Path: [email protected]' . "\r\n"; 
mail($to, $subject, $message, $headers, '[email protected]'); 
?> 
+0

在你的CSS而不是'背景'嘗試'bgcolor'或'background-color' – Chris

+0

@Chris - 我測試過但不能工作,謝謝^^可能是gmail不生成類似hotmail和yahoo的類? –

+1

也許最好直接設計'a'而不是'td'? – Chris

回答

1

Gmail不支持head標籤中的嵌入式css。不過你可以試試這個:

<html> 
 
     <body style='margin: 0; padding: 0;font-family: \&quot;Helvetica Neue\&quot;, Helvetica, Arial, sans-serif;'> 
 
      <table align='center' style='margin:auto;'> 
 
       <tbody> 
 
        <tr> 
 
         <style scoped> 
 
         td { 
 
          color: #a7a7a2; 
 
          background: green; 
 
          padding: 2px 14px; 
 
          border-radius: 10px; 
 
         } 
 
         </style> 
 
         <td> 
 
         <a href='test.php' target='_blank' style='padding: 11px 0px; display:block; text-decoration:none; color:#000; font-size:16px; text-align:center; font-family:arial; font-weight:bold'>TEST BUTTON</a> 
 
         </td> 
 
        </tr> 
 
       </tbody> 
 
      </table> 
 
     </body> 
 
    </html>

上述適用風格孩子td而不是整個文件。

+0

喜歡添加樣式到td標籤? –

+0

我不明白你在問什麼 – Chris

相關問題