php - 使用 PHPMailer 发送 HTML 格式的邮件
问题描述
我需要发送包含 PHP 页面内容的电子邮件,但我遇到了麻烦,尽我所能在 HTML 中创建静态格式,但如果明天数据有更多行,电子邮件将不完整,我将分享部分内容我的邮件.php
//The query
$wipAgingQuery = $dbconnection->query("
SELECT
CAST(datein AS DATE) AS [Date_In],
COUNT(lab) AS [Count_of_Jobs],
ROUND(SUM(COUNT(lab)) OVER (ORDER BY datein DESC) * 100.0 / SUM(COUNT(lab)) OVER (),2) AS [Cumulative]
FROM [DailyWIP].[dbo].[WIP_Daily_Load]
WHERE location = 'USA' AND dateload BETWEEN CONCAT(CAST(GETDATE() AS DATE),' 11:30:00.000') AND CONCAT(CAST(GETDATE() AS DATE),' 14:00:00.000')
GROUP BY datein ORDER BY datein DESC;");
$jobInWip = $wipAgingQuery->fetchAll(PDO::FETCH_OBJ);
//Assign Query Result in Variable
foreach ($jobInWip as $jobInWip) {
$wipDateIn = $jobInWip -> Date_In;
$wipCount = $jobInWip -> Count_of_Jobs;
$wipCumulative = $jobInWip -> Lab_Cumulative;
$totalJobCount = $totalJobCount + $wipCount;
}
//HTML inside the Mailer Body
<div class='row'>
<div class='col-12'>
<h1>Current Day WIP: Aging</h1>
<table class='table table-bordered'>
<thead class='thead-dark'>
<tr>
<th>Date In</th>
<th>Count of Jobs</th>
<th>Lab Cumulative</th>
</tr>
</thead>
<tbody>
<tr>
<td>$wipDateIn</td>
<td><p class='text-right'>$wipCount</p></td>
<td><p class='text-right'>$wipCumulative</td>
</tr>
<tr>
<td>Grand Total:</td>
<td><p class='text-right'>$totalJobCount</p></td>
</tr>
</tbody>
</table>
</div>
</div>
这是原始的 wipdata.php 页面,我可以在其中管理该问题,因为表是由 foreach 根据查询结果创建的,但我不知道如何在 mail.php 中执行类似的操作
<div class="row">
<div class="col-12">
<h1>Current Day WIP: Aging</h1>
<br>
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Date In</th>
<th>Count of Jobs</th>
<th>Lab Cumulative</th>
</tr>
</thead>
<tbody>
<?php foreach ($jobInWip as $jobInWip) { ?>
<tr>
<td><?php echo $jobInWip->Date_In ?></td>
<td><?php echo '<p class="text-right">'. number_format($jobInWip->Count_of_Jobs) .'</p>' ?></td>
<td><?php echo '<p class="text-right">'. number_format($jobInWip->Lab_Cumulative, 2) . ' %' ?></td>
</tr>
<?php $totalJobCount = $totalJobCount + $jobInWip->Count_of_Jobs;
} ?>
<tr>
<td><?php echo 'Grand Total: ' ?></td>
<td><?php echo '<p class="text-right">'. number_format($totalJobCount).'</p>'; ?></td>
</tr>
</tbody>
</table>
</div>
</div>
解决方案
哦,我刚刚找到了解决这个问题的方法,我不确定这是否是解决它的最佳方法,但它确实有效。
foreach ($jobInWip as $jobInWip) {
$wipDateIn = $jobInWip -> Date_In;
$wipCount = $jobInWip -> Count_of_Jobs;
$wipCumulative = $jobInWip -> Lab_Cumulative;
$totalJobCount = $totalJobCount + $wipCount;
$phpmailer-> Body .="<tr>
<td>$wipDateIn</td>
<td><p class='text-right'>$wipCount</p></td>
<td><p class='text-right'>$wipCumulative</td>
</tr>";}
推荐阅读
- bash - pdftex 在 bash 脚本中失败
- php - 使用 https 但使用 http 时出现 Alamofire 标头错误
- php - 如何将数据从 MSSQL 添加到 Ext.Net 7.2.0 经典版
- javascript - 无法启动模拟器。原因:没有找到模拟器作为 `emulator -list-avds` 的输出
- sql-server - 是否可以在系统版本表的查询中动态删除 FOR SYSTEM_TIME?
- java - @Query 结果到 DTO 导致 spring data jpa 中的构造函数错误
- python - 在 EC2 实例中的文件夹之间移动文件的问题
- node.js - 我似乎无法安装 Sqlite3
- python - Plotly:如何更改 3D 曲面图的配色方案?
- linux - 为什么while循环中的语法错误会中断脚本(但不会在while循环之外)