2013-05-07 40 views
0

我通過ajax調用將內容從html發佈到php。我想發送一封包含該發佈內容的HTML電子郵件。我回應了所有內聯CSS的發佈數據。但在郵件中,我只能看到沒有CSS效果的html內容。Html電子郵件忽略所有內嵌的CSS(已解決)

我的html代碼將有一些靜態內容與內容可編輯功能。

  <form id="form"name="form" method="post" action="xyz.php" onsubmit="this.divcontent.value = document.getElementById('email_body').innerHTML;"> 
      <input type="hidden" name="divcontent" id="divcontent" value="" /> 
      <div id="email_body" class="field" role="textbox" contenteditable="true"> 
      <div style="....">......</div> 
      <a>.....</a> 
      <div style="....">....</div> 
      <div style="....">....</div> 
      </div> 
      <div class="send_mail"><button type="submit">Send</button></div> 
      </form> 

我Ajax調用

   $.ajax({ 
         type : 'POST', 
         url : $("#form").attr('action'), 
         data : fields, 
         dataType : 'json', 
         success: function() {......}....}); 

我的PHP代碼與無CSS效果發送郵件。

 <? 
      $email_body = $_POST[divcontent]; 
      $headers .= "MIME-Version: 1.0\r\n"; 
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 




         //create email headers 
         $headers .= 'From: '.$email_from."\r\n". 
         'Reply-To: '.$emailid_from."\r\n" . 
         'X-Mailer: PHP/' . phpversion(); 
         @mail($email_to, $email_subject, $email_body, $headers); 
       $array = array('error' => false, 'message' => $message); 
       echo json_encode($array); 
       echo json_encode($array); 
    ?> 


any suggestions? 
+0

我在這裏沒有看到任何內聯CSS,你可以顯示它應該在哪裏? – 2013-05-07 18:41:08

+0

@Pekka 0123'

....
' – j08691 2013-05-07 18:41:36

+1

好的,但我想看到實際的風格 – 2013-05-07 18:42:44

回答

0

$ EMAIL_BODY =的stripslashes($ _ POST [divcontent]);解決了我的問題。感謝所有的答覆。

1

當您設計新聞簡報時,最好將文字包裝在字體標籤中。電子郵件客戶端對他們的解析非常非常挑剔。你應該像1990年一樣編寫代碼(使用表格)。

<font face="verdana" color="green">This is some text!</font> 

字體標籤:http://www.w3schools.com/tags/tag_font.asp

1

很多內嵌樣式是從電子郵件客戶端(臺式機和基於Web)由於​​安全,渲染,和廣告的問題刪除。您的<div>標籤上的內聯樣式很可能會被剝離。目前的最佳做法是使用<p>標籤代替font-sizecolor樣式。

有關更多詳細信息,請查看Campaign Monitor上的CSS SupportE-mail Design Guidelines

0

您需要使用的CSS內聯,就像這樣:

<div style="width:300px; margin: 10;">Content!</div> 

<font style="font-size:14px">Text</font>