2017-06-20 84 views
2

我試圖給這個html郵件添加背景顏色。如何添加背景顏色到用PHP郵件發送的html郵件()

伊夫試圖把在

  • <script>標籤與CSS代碼中
  • 的bgcolor身體標記
  • 和CSS樣式表

    所有這一切都沒有工作。 我讀過它可能是提供者(gmail)我正在發送這些測試,但必須有一種方法。

我已經在一個單獨的.html文件上測試了所有的方法,這些方法都改變了我想要的。我只是不能在實際的電子郵件中得到它。我在php中使用mail()。

$message = " 
    <html> 
    <head> 
    <title>Rate Your Experience</title> 
    </head> 
    <body bgcolor = '#0000FF'> 
    <center> 

    <p> 
     <h2>How well did '$recipient' do?</h2> 
     <h4>Vacancy Title: '$vac_title'</h4> 
     <h4>Vacancy ID: '$vac_id'</h4> 
    </P> 
    </center> 
    <center> 
     <table> 
     <tr> 
     <td><h3>we are built on sharing your review with other people who may also want to use this service.</h3></td> 
     </tr> 
     <tr> 
     <td><h3>Please take a minute to reflect on the level of service youve received.</h3></td> 
     </tr> 
     <tr> 
     <td><h3>Your review is public - to other employers registered with Ahoy Employ.</h3></td> 
     </tr> 
     <tr> 
     <td><h3>Should you have any concerns that you would prefer to share in private, please email us at [email protected] and quote the Vacancy ID shown above.</h3></td> 
     </tr> 
     </table> 
    </center> 
    </body> 
    </html> 
    "; 

    // Always set content-type when sending HTML email 
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

    // More headers 
    $headers .= 'From: <[email protected].ca>' . "\r\n"; 

    mail($to,$subject,$message,$headers); 
+0

您可以編寫內聯格式的電子郵件例如('') –

+0

基本的內嵌CSS將完成您所需的操作。 –

回答

2

嘗試像這樣:

<body style="background-color:#cfcfcf";> 
+1

內聯的CSS工作它只需要singel報價而不是雙。 –

0

首先要了解電子郵件是扔掉你知道Web標準的一切。電子郵件仍然在90年代。看看Litmus和MailChimp在說什麼。

  1. 使用表格進行設計。
  2. 使用表格作爲容器。將整個消息包裝在單列,單行表中。

然後use the bgcolor of that table爲您的電子郵件背景着色。

忘掉使用外部樣式表或使用<style>標籤將CSS放在標題中。他們被各種讀者剝離出來。你必須在html標籤中做內聯樣式。

是的,它擊敗了CSS的全部目的。但正如我所說,電子郵件不符合標準。它落後了。

0

如果您使用的是電子郵件模板,那麼您可以在標籤中編寫嵌入式CSS以及嵌入式CSS。

其他方面,你可以在你的html代碼中編寫內聯的css。

  • 如果您使用的是外部css然後它可能不會工作在Gmail收件箱的電子郵件找不到css的路徑。