2010-06-25 141 views
2

我想用html模板發送一封郵件。郵件已發送。但我找不到那封郵件中的設計。如何用設計發送郵件。如何使用PHP將HTML模板作爲郵件發送?

郵件應該看起來像我在我的html模板中查看。

如何做到這一點?友善的建議。

在此先感謝。

我的代碼:

$subject = "Hi this is subject"; 
$email = "[email protected]"; 
$message = "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Super Qpon </title> 
</head> 
<link rel="stylesheet" href="../stylesheet/common.css" type="text/css"> 
<body> 

<div class="mainbodycontainer"> 
<div class="gift"> 
<div class="gft-top"></div> 
<div class="gft-bg"> 
<div class=""> 
<h1 class="title">Gift Coupon</h1> 
<div class="toppm"> 
<div class="coupon"> 
<div class="cop-top"></div> 
<div class="cop-bg"> 
<div> 
<table width="165" align="right" border="0" cellpadding="0" cellspacing="0"> 
<tr> 
<td width="81" class="t5">Coupon No :</td> 
<td width="84">SQ548555</td> 
</tr> 
</table> 
<div class="spacer"></div> 
</div> 
<div class="toppm"> 
<table width="500" border="0" cellpadding="0" cellspacing="0"> 
<tr> 
<td width="99" height="30">From</td> 
<td width="15" align="center">:</td> 
<td width="386">test</td> 
</tr> 
<tr> 
<td height="30">Amount</td> 
<td align="center">:</td> 
<td>$560</td> 
</tr> 
</table> 
<div class="spacer"></div> 
</div> 
<div class="toppm"> 
<table width="165" align="right" border="0" cellpadding="0" cellspacing="0"> 
<tr> 
<td width="81" class="t5">CODE NO :</td> 
<td width="84">SQ548555</td> 
</tr> 
</table> 
</div> 
<div class="spacer"></div> 
</div> 
<div class="cop-btm"></div> 
<div class="spacer"></div> 
</div> 
<div class="spacer"></div> 
</div> 
<div class="spacer"></div> 
</div> 
<div class="spacer"></div> 
</div> 
<div class="gft-btm"></div> 
<div class="spacer"></div> 
</div> 
<div class="spacer"></div> 
</div> 

</body> 
</html>"; 


$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= 'From: SuperQpon <[email protected]>' . "\r\n"; 
mail($email,$subject,$message,$headers); 

回答

2

如果定義在標籤的屬性所有樣式這將是更美好簡化你的生活了很多。像這樣(style =「background-color:#aefd34;」)。

我面臨類似的問題,但是當我在樣式屬性中定義CSS時,一切正常。

+0

你的CSS這解決了我的問題太。謝謝 – Fero 2010-07-03 08:12:08

+0

@Fero:不客氣 – 2010-07-06 05:59:52

1

您的問題可能在於這裏:

<link rel="stylesheet" href="../stylesheet/common.css" type="text/css">

該樣式需要,如果你想,要工作要鏈接到電子郵件。相對路徑指的是它位於您的計算機/服務器上的位置 - 收到時將從電子郵件中刪除。

編輯

您可以通過使用http://postageapp.com/

+0

可否請你提供一個解決方案來做到這一點?我有點困惑。我已經將整個服務器路徑放在系統包含樣式表的地方。還有其他選擇嗎? – Fero 2010-06-25 05:28:01

+1

雖然我不知道如何在HTML中引用樣式表,但可以將樣式表作爲附件包含在內。它也可以內聯提供。 – staticsan 2010-06-25 06:04:51

+0

退房postageapp – 2010-06-25 06:17:11

0

儘管您需要知道電子郵件不是Web,並且電子郵件客戶端的HTML呈現之間的差異遠遠大於Web瀏覽器,但您可以使用任何您喜歡的模板系統(例如Smarty)來生成電子郵件內容。看看www.email-standards.org瞭解更多細節。我建議你使用一個庫來發送你的信息,例如PHPMailer,SwiftMailer,Zend_Mail等。 要做鏈接到內聯樣式的自動轉換(加上對你的內容的電子郵件兼容性的批評),看看premailer