很抱歉这样一个菜鸟问题,但我到处搜索,发现几乎没有帮助。 我有一个 mysql 数据库发送用 html 编写的简单收据。 根据请求,php 文件应该从 mysql 加载数据,html 发送正常,但在显示 php 查找 html 中的信息时遇到麻烦:
<?php
$data2 = "12/12/14";
$message =
'<html>
<head>
<meta http-equiv=Content-Language content=en-us>
<meta name=ProgId content=FrontPage.Editor.Document>
<meta http-equiv=Content-Type content=text/html; charset=windows-1252>
<title>DRAFT</title>
</head>
<body leftmargin=50>
<table cellpadding=0 cellspacing=0 width=808 height=115>
<!-- MSTableType=layout -->
<tr>
<td align=center width=206>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=4 -->
<tr>
<td bgcolor=#000000 colspan=2 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td bgcolor=#000000 width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
<td align=center valign=middle height=100% width=100%>
<!-- MSCellFormattingType=content -->
<b>****</b><br>
101 SomeStreet Rd.<br>
City, State, Zip<br>
Office: ****<br>
Fax: ****<br>
</td>
</tr>
</table>
</td>
<td valign=top width=275 height=115>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=3 -->
<tr>
<td bgcolor=#000000 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td valign=top height=100% width=100%>
<!-- MSCellFormattingType=content -->
</td>
</tr>
</table>
</td>
<td valign=top height=115 width=327>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=2 -->
<tr>
<td bgcolor=#000000 colspan=2 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td valign=top width=100%>
<!-- MSCellFormattingType=content -->
Date <u><?php echo $data2; ?></u><br>
Year ___<u>%year%</u>__ Mileage __<u>%mileage%</u>__<br>
Make __<u>%make%</u>__ Model __<u>%model%</u>__<br>
Vin# __<u>%VIN%</u>__<br>
Color __<u>%color%</u>__ Trim: __<u>%trim%</u>_____</td>
<td bgcolor=#000000 height=100% width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 width=808 height=263>
<!-- MSTableType=layout -->
<tr>
<td valign=top bordercolordark=#000000 bordercolor=#000000 height=184>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=1 -->
<tr>
<td bgcolor=#000000 colspan=3 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td bgcolor=#000000 width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
<td valign=top bordercolordark=#000000 bordercolor=#000000 width=100%>
<!-- MSCellFormattingType=content -->
<b> PAY TO THE <br>
ORDER OF</b>
___<u>%dealername%</u>______<u>%soldprice%</u>___<br>
<br>
__<u>%num2word%</u>__;
<b>DOLLARS</b><p><font size=2> <br>
*****/OWNER<br>
OFFICE:******; SIGNATURE</font></td>
<td bgcolor=#000000 height=100% width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td bgcolor=#000000 colspan=3 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=79 width=808> </td>
</tr>
</table>
<p> </p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
mail($BidEmail, " test", $message, $headers);
?>
用 :
$message =
"<html>
<head>
<meta http-equiv=Content-Language content=en-us>
<meta name=ProgId content=FrontPage.Editor.Document>
<meta http-equiv=Content-Type content=text/html; charset=windows-1252>
<title>DRAFT</title>
</head>
<body leftmargin=50>
<table cellpadding=0 cellspacing=0 width=808 height=115>
<!-- MSTableType=layout -->
<tr>
<td align=center width=206>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=4 -->
<tr>
<td bgcolor=#000000 colspan=2 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td bgcolor=#000000 width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
<td align=center valign=middle height=100% width=100%>
<!-- MSCellFormattingType=content -->
<b>****</b><br>
101 SomeStreet Rd.<br>
City, State, Zip<br>
Office: ****<br>
Fax: ****<br>
</td>
</tr>
</table>
</td>
<td valign=top width=275 height=115>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=3 -->
<tr>
<td bgcolor=#000000 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td valign=top height=100% width=100%>
<!-- MSCellFormattingType=content -->
</td>
</tr>
</table>
</td>
<td valign=top height=115 width=327>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=2 -->
<tr>
<td bgcolor=#000000 colspan=2 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td valign=top width=100%>
<!-- MSCellFormattingType=content -->
Date <u>$data2</u><br>
Year ___<u>%year%</u>__ Mileage __<u>%mileage%</u>__<br>
Make __<u>%make%</u>__ Model __<u>%model%</u>__<br>
Vin# __<u>%VIN%</u>__<br>
Color __<u>%color%</u>__ Trim: __<u>%trim%</u>_____</td>
<td bgcolor=#000000 height=100% width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 width=808 height=263>
<!-- MSTableType=layout -->
<tr>
<td valign=top bordercolordark=#000000 bordercolor=#000000 height=184>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<!-- MSCellFormattingTableID=1 -->
<tr>
<td bgcolor=#000000 colspan=3 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td bgcolor=#000000 width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
<td valign=top bordercolordark=#000000 bordercolor=#000000 width=100%>
<!-- MSCellFormattingType=content -->
<b> PAY TO THE <br>
ORDER OF</b>
___<u>%dealername%</u>______<u>%soldprice%</u>___<br>
<br>
__<u>%num2word%</u>__;
<b>DOLLARS</b><p><font size=2> <br>
*****/OWNER<br>
OFFICE:******; SIGNATURE</font></td>
<td bgcolor=#000000 height=100% width=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
<tr>
<td bgcolor=#000000 colspan=3 height=1>
<img alt= width=1 height=1 src=MsSpacer.gif></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=79 width=808> </td>
</tr>
</table>
<p> </p>
</body>
</html>";
尝试更改此行:
Date <u><?php echo $data2; ?></u><br>
自:
Date <u>'. $data2 . '</u><br>
有点
不清楚,但我认为你应该在%something%
的地方加入值
'html content '.htmlspecialchars($something).' more html content'
定义
这样一个$message,其中有许多特殊字符和php变量,这不是好方法。
用户使用变量或长文本定义变量的方法如下:
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
此外,定义该消息的最佳方法是在 html 文件中,然后使用 function 获取 html
$message = file_get_contents("http://www.example.com/abc.html")
通过这种方式,很容易将电子邮件部分与电子邮件发送功能分开。
如果你真的想要像你的方式:
$message ="消息的第一部分" 。 $data . "你消息的第二部分" .
希望这对您有所帮助。