2010-06-25 135 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