在phpmailer中发送动态表 [英] Sending dynamic table in phpmailer

查看:60
本文介绍了在phpmailer中发送动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过php mailer发送电子邮件时遇到问题.我正在尝试发送动态填充的表,但是我只收到电子邮件中的第一行. 如果有人对我如何通过电子邮件发送整个表格有任何了解,请分享!谢谢!

I am having an issue with sending an email through php mailer. I am trying to send a dynamically populated table but I am only receiving the first row in the emails. If anyone has any knowledge on how I can send the full table in an email please share! Thank you!

这是我遇到问题的代码.

Here is my code where I am having issues.

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $_POST['subject'];
While($row=mysql_fetch_assoc($result)){
$end_dt = $row['end_dt'];
$dpd = floor((abs(strtotime(date("Y-m-d")) - strtotime($end_dt))/(60*60*24)));
$mail->Body    =
"<table><tr><th>Name</th><th>IDCourseTax</th><th>TDCourse</th><th>End Date</th><th>Tax   Rate</th><th>Days past due</th></tr>
<tr><td>".$row["course"]."</td><td>".$row["IDCourseTax"]."</td><td>".$row["IDCourse"]."  </td><td>".$row["end_dt"]."</td><td>".$row["tax_rate"]."</td><td>".$dpd."</td></tr>  </table>"; }

推荐答案

您正在循环中编写表,因此每次迭代都会覆盖该表.

You are writing the table in the loop so on each iteration it is getting overwritten.

您将要在变量中创建表,然后将主体设置为该变量:

You will want to create your table in a variable then set the body to that variable:

$mail->isHTML(true); // Set email format to HTML

$mail->Subject = $_POST['subject'];

$body = '<table><tr><th>Name</th><th>IDCourseTax</th><th>TDCourse</th><th>End Date</th><th>Tax   Rate</th><th>Days past due</th></tr>';

while($row=mysql_fetch_assoc($result)) {
    $end_dt = $row['end_dt'];
    $dpd = floor((abs(strtotime(date("Y-m-d")) - strtotime($end_dt))/(60*60*24)));
    $body .= "<tr><td>".$row['course']."</td><td>".$row['IDCourseTax']."</td><td>".$row['IDCourse']."  </td><td>".$row['end_dt']."</td><td>".$row['tax_rate']."</td><td>".$dpd."</td></tr>"; 
}

$mail->Body = $body.'</table>';

这篇关于在phpmailer中发送动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆