2016-11-17 45 views
0

電子郵件下面是我用於發送電子郵件CSS打破HTML表使用PHP

$to = '[email protected]'; 
$subject = "Edufly Global Studies"; 

$message = file_get_contents("email_template.html"); 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n"; 

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

並在文件email_template.html

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>[SUBJECT]</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> 


</head> 
<body style="padding: 15px 100px 15px 100px"> 
<div class="col-md-6 col-md-offset-3"> 
<h1>TAT time for stages</h1> 
<table class='table table-striped table-bordered'> 
<tr> 
    <th>From Stage</th> 
    <th>To Stage</th> 
    <th>TAT Time</th> 
</tr> 
<tr> 
<td>Telecounselling</td> 
<td>Counselling</td> 
<td>25 days</td> 
</tr> 
<tr> 
<td>Counselling</td> 
<td>Documentation</td> 
<td>7 days</td> 
</tr> 
<tr> 
<td>Documentation</td> 
<td>Offer Application</td> 
<td>2 days</td> 
</tr> 
<tr> 
<td>Offer Application</td> 
<td>Offer Received (New)</td> 
<td>30 days</td> 
</tr> 
<tr> 
<td>Offer Received</td> 
<td>Visa Applied</td> 
<td>25 days</td> 
</tr> 
<tr> 
<td>Visa Applied</td> 
<td>Visa Received (New)</td> 
<td>20 days</td> 
</tr> 
<tr> 
<td>Visa Received</td> 
<td>Payment</td> 
<td>60 days</td> 
</tr> 
</table> 
</div> 
    </body> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    </html> 

代碼如果我單獨運行HTML代碼,它的自舉表格式像下面的截圖

enter image description here

但在郵件我收到升IKE格式化表格

enter image description here

我this.Please任何人做了哪些錯誤幫我走出這個問題。 在此先感謝。

+0

Obvioulsy從您的CDN css文件將被忽略。使用內聯樣式。 –

+0

同時發送電子郵件使用內聯CSS。嘗試尋找電子郵件模板。 –

+0

我嘗試了內嵌的css too.Now也沒有格式化表格到我的電子郵件 –

回答

0

可以使用message參數發送這樣的內容你mail身體,

$message = '<html><body>'; 
$message .= '<img src="header.png" alt="Website Change Request" />'; 
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; 
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>"; 
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>"; 
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>"; 
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>"; 
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>"; 
$addURLS = $_POST['addURLS']; 
if (($addURLS) != '') { 
    $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>"; 
} 
$curText = htmlentities($_POST['curText']);   
if (($curText) != '') { 
    $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>"; 
} 
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>"; 
$message .= "</table>"; 
$message .= "</body></html>"; 
+0

對於很長的html代碼我該如何補充這樣的 –

+0

即使這樣如何可以添加引導表與這個內容 –

+0

我認爲它只是一個表只是寫自己的CSS更好@KavyaShree – Karthi

0

當你打開模板,它顯示了正確的合身,因爲引導已加載瀏覽器(這裏舉使格式化)

但是從電子郵件打開它,它顯示了不格式化,因爲引導是不存在的,這是顯而易見的事情。

所以如果你需要有良好的格式化模板,你應該適用於你的模板本身內嵌CSS(我的意思是不應該有任何的CSS文件包括)

+0

然後我可以下載引導CSS和存儲在本地的css文件的權利 –