doubijiao2094 2014-06-26 17:24
浏览 18
已采纳

在phpmailer中发送动态表

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>"; }
  • 写回答

2条回答 默认 最新

  • douwo1862 2014-06-26 17:36
    关注

    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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改