使用PHPMailer发送HTML格式的邮件
我需要发送包含PHP页面内容的电子邮件,但我遇到了麻烦,我只能用HTML创建静态格式,但如果明天数据有更多行,电子邮件将不完整, 我将分享我的mail.php的一部分使用PHPMailer发送HTML格式的邮件,php,html,phpmailer,Php,Html,Phpmailer,我需要发送包含PHP页面内容的电子邮件,但我遇到了麻烦,我只能用HTML创建静态格式,但如果明天数据有更多行,电子邮件将不完整, 我将分享我的mail.php的一部分 //The query $wipAgingQuery = $dbconnection->query(" SELECT CAST(datein AS DATE) AS [Date_In], COUNT(lab) AS [Count_of_Jobs],
//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>
//查询
$wipAgingQuery=$dbconnection->query(“
挑选
铸造(日期为日期)为[日期],
将(实验室)计算为[工作数量],
四舍五入(总和(计数(实验室))超过(描述中按日期排序)*100.0/总和(计数(实验室))超过(),2)为[累计]
来自[DailyWIP].[dbo].[WIP\U每日加载]
其中位置='USA'和日期加载介于CONCAT(CAST(GETDATE()作为日期),'11:30:00.000')和CONCAT(CAST(GETDATE()作为日期),'14:00:00.000')之间
按日期分组,按日期排序,以“;”号填列;
$jobInWip=$wipAgingQuery->fetchAll(PDO::FETCH_OBJ);
//在变量中分配查询结果
foreach($jobInWip作为$jobInWip){
$wipDateIn=$jobInWip->Date\U In;
$wipCount=$jobInWip->作业计数;
$WIP累计=$jobInWip->Lab_累计;
$totalJobCount=$totalJobCount+$wipCount;
}
//邮件正文中的HTML
当日在制品:账龄
约会
工作计数
实验室累积
$wipDateIn
$wipCount
总计:
$totalJobCount
这是原始的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>";}
foreach($jobInWip作为$jobInWip){
$wipDateIn=$jobInWip->Date\U In;
$wipCount=$jobInWip->作业计数;
$WIP累计=$jobInWip->Lab_累计;
$totalJobCount=$totalJobCount+$wipCount;
$phpmailer->Body.=”
$wipDateIn
$wipCount
";}