开发者

How to send a HTML template as mail using PHP?

I am trying to send a mail with html template. The mail was sent. but i can't find the design there in that mail. How to send the mail with the design.

The mail should exactly look like what i view in my html template.

How to do this? kindly advice.

Thanks in advance.

My code:

$subject = "Hi this is subject";
$email   = "x@x.com";
$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 <admin@superQpon.com>' . "\r\n";
mail($email,$subject,$message,$headers );


It would be more better if you define all your styles in the tag's attributes. like this (style="background-color:#aefd34;").

I faced the similar problem but when I defined the CSS in the style attribute all went fine.


Your problem may lie here:

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

This stylesheet needs to be linked into the email if you want that to work. The relative path refers to where it lies on your computer/server - which will be inaccesible from the email when received.

EDIT

You can simplify your life a lot by using http://postageapp.com/


You can use any templating system you like (e.g. Smarty) to produce email content, though you need to be aware that email is not the web, and differences between email clients' HTML rendering are far greater than web browsers. Take a look at www.email-standards.org for more detail on that. I suggest you use a library to send your rendered messages though, such as PHPMailer, SwiftMailer, Zend_Mail etc. To do automated conversion from linked to inline styles (plus critique of email compatibility of your content), take a look at premailer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜