Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP将HTML模板作为邮件发送?_Php_Email - Fatal编程技术网

如何使用PHP将HTML模板作为邮件发送?

如何使用PHP将HTML模板作为邮件发送?,php,email,Php,Email,我正在尝试发送带有html模板的邮件。邮件已发送。但是我在那封信里找不到设计。如何发送带有设计的邮件 邮件应该与我在html模板中看到的内容一模一样。 如何做到这一点?好心的建议 提前谢谢 我的代码: $subject = "Hi this is subject"; $email = "x@x.com"; $message = "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o

我正在尝试发送带有html模板的邮件。邮件已发送。但是我在那封信里找不到设计。如何发送带有设计的邮件

邮件应该与我在html模板中看到的内容一模一样。

如何做到这一点?好心的建议

提前谢谢

我的代码:

$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 );
$subject=“你好,这是subject”;
$email=”x@x.com";
$message=”
超级Qpon
礼券
优惠券编号:
SQ548555
从…起
:
测试
数量
:
$560
代码:
SQ548555
";
$headers='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
$headers.='From:SuperQpon'。“\r\n”;
邮件($email、$subject、$message、$headers);

您的问题可能在于:

如果您希望此样式表起作用,则需要将其链接到电子邮件中。相对路径指的是它在您的计算机/服务器上的位置-在收到电子邮件时,将无法从电子邮件中访问

编辑


使用

可以大大简化您的生活。如果您在标记的属性中定义所有样式,效果会更好。像这样(style=“background color:#aefd34;”)


我也遇到了类似的问题,但当我在style属性中定义CSS时,一切都很顺利。

你可以使用任何你喜欢的模板系统(例如Smarty)来生成电子邮件内容,尽管你需要意识到电子邮件不是web,电子邮件客户端的HTML呈现之间的差异远远大于web浏览器。请访问www.email-standards.org了解更多详细信息。我建议您使用一个库来发送呈现的消息,例如PHPMailer、SwiftMailer、Zend_-Mail等。
要实现从链接样式到内联样式的自动转换(加上对您内容的电子邮件兼容性的评论),请查看

您能为我提供一个解决方案吗?我对此有点困惑。我已经给出了系统包含样式表的整个服务器路径。还有其他选择吗?可以将样式表作为附件包含在内,尽管我不知道如何在HTML中引用它。它也可以内联提供。也许将CSS放在实际的html文件中会起作用(在head部分),例如://这里是您的CSS