PHP文件中生成HTML报表
主要步骤
目的,php文件发送邮件,邮件内容包含报表。写在一个文件中,让html页面里的一个标签的value值设置成php传递的数据;优化方法,数据写到一个文件里,用js去取数据,使用三个文件index.php,index.html,
- 写好HTML报表样式
- php文件,前端页面结果,生成报表------如何读取结果-----从数据库读取信息
- 报表样式html格式,直接在邮件里面生成-------单独写,传入结果;
邮件样式,写到PHP文件
邮件报表样式设置
public function writeEmailHead($title){
$html = "";
$html = $html."<!DOCTYPE html><html lang=\"zh\"><head><meta charset=\"UTF-8\"><title>".$title."</title><style type=\"text/css\">".
"body {color:#333;font:14px Arial, Helvetica, sans-serif, Simsun;}".
".title {font-weight:bold} p{font-size:17px}".
".subtitle {margin-top: 3px; margin-bottom: 3px;}".
"table {width:50%;border-collapse:collapse;border-spacing:0;white-space:nowrap}".
".table-status th {height:32px;width:105px;line-height:20px;padding:0 10px;font-size:14px;font-weight:600;text-align:left;border:1px solid #000;white-space:nowrap;}".
".foot{margin-top: 100px;font-size: 13px;}".
"</style></head>".
"<body>";
return $html;
}
PHP语句与html同时存在
html与PHP语句之间,通过以下格式连接
$html .=<<<EOF... EOF;
public function writeEmailCaseContent($caseNum,$params){
$html = '';
$html .= <<<EOF
<div>
<h3>详情</h3>
<article class="first-level-article">
<table class="table-status" >
<thead style="background-color: #fff;">
<tr>
<td class="first-th ng-binding" >序号</td>
<td class="first-th ng-binding">ID</td>
</tr>
</thead>
<tbody >
EOF;
for($i = 0; $i < $caseNum; $i++){
$testID = $params[$i]['testID'];
$html .= "<tr><td>$i</td>";
$html .= "<td>$testID</td>";
}
$html .= "</tbody></table></article></div>";
return $html;
}
html 根据报表内容调节样式
style=white-space:nowrap;