使用PHPMailer发送表数据

使用PHPMailer发送表数据,php,email,mysqli,Php,Email,Mysqli,我有一条可以从数据库中提取的记录。我希望能够使用PHPMailer将此表格报告发送到电子邮件。现在的问题是:发送邮件时,它只显示表格的标题部分,而不显示内容。请参阅下面的代码,也许有人可以告诉我缺少什么或更好的方法: $mail->Body = "<p>Please find below the Action Plan for Routine Report that is generated based on today's Check.</p><br

我有一条可以从数据库中提取的记录。我希望能够使用PHPMailer将此表格报告发送到电子邮件。现在的问题是:发送邮件时,它只显示表格的标题部分,而不显示内容。请参阅下面的代码,也许有人可以告诉我缺少什么或更好的方法:

$mail->Body    =  "<p>Please find below the Action Plan for Routine Report that is generated based on today's Check.</p><br/>".
                  "<table width='100%' border='1' style='margin-top:15px;' align='left class='table table-striped'>". 
                  "<thead><tr>".
                  "<th>SN</th>".
                  "<th nowrap='nowrap'>Mainlocation</th>".
                  "<th nowrap='nowrap'>Sub-Loaction</th>".
                  "<th nowrap='nowrap'>Issue</th>".
                  "<th nowrap='nowrap'>Current Plan</th>".
                  "<th nowrap='nowrap'>Who</th>".
                  "<th nowrap='nowrap'>When</th>".
                  "</tr></thead><tbody>".
                  $qq = mysqli_query($con,"SELECT * FROM tab_trans WHERE transid='$transid' ORDER BY subloc");
                  $d =0;
                  while($c = mysqli_fetch_array($qq)){ $d++;
                  "<tr>".
                  "<td nowrap='nowrap'>".$d."</td>".
                  "<td nowrap='nowrap'> ".$c['mainloc']."</td>".
                  "<td nowrap='nowrap'> ".$c['subloc']."</td>".
                  "<td nowrap='nowrap'> ".$c['issue']."</td>".
                  "<td nowrap='nowrap'> ".$c['what']."</td>".
                  "<td nowrap='nowrap'> ".$c['who']."</td>".
                  "<td nowrap='nowrap'> ".$c['period']."</td></tr>";
                  }
                  "</tbody></table>";
$mail->Body=“请在下面找到根据今天的检查生成的例行报告的行动计划。


”。
“谢谢大家。解决方法是:循环是有问题的循环。它无法得到结果。因此,将$mail->body与少量修改结合起来解决问题:

$mail->Body    =  "<p>Please find below the Action Plan for Routine Report that is generated based on today's Check.</p><br/>".


                     "<table width='100%' border='1' style='margin-top:15px;' align='left class='table table-striped'>". 
                      "<thead><tr>".
                      "<th>SN</th>".
                      "<th nowrap='nowrap'>Mainlocation</th>".
                      "<th nowrap='nowrap'>Sub-Loaction</th>".
                      "<th nowrap='nowrap'>Issue</th>".
                      "<th nowrap='nowrap'>Current Plan</th>".
                      "<th nowrap='nowrap'>Who</th>".
                      "<th nowrap='nowrap'>When</th>".
                      "</tr></thead><tbody>";
                      $qq = mysqli_query($con,"SELECT * FROM tab_trans WHERE transid='$transid' ORDER BY subloc");
                      $d =0;
                      while($c = mysqli_fetch_array($qq)){ $d++;
  $mail->Body.=       "<tr>".
                      "<td nowrap='nowrap'>".$d."</td>".
                      "<td nowrap='nowrap'> ".$c['mainloc']."</td>".
                      "<td nowrap='nowrap'> ".$c['subloc']."</td>".
                      "<td nowrap='nowrap'> ".$c['issue']."</td>".
                      "<td nowrap='nowrap'> ".$c['what']."</td>".
                      "<td nowrap='nowrap'> ".$c['who']."</td>".
                      "<td nowrap='nowrap'> ".$c['period']."</td></tr>";
                      }
$mail->Body.=       "</tbody></table>";
$mail->Body=“请在下面找到根据今天的检查生成的例行报告的行动计划。


”。
“您的代码易受SQL注入攻击。您应该使用或准备语句,如中所述。@AlexHowansky:谢谢,我现在从数据库获取数据,而不是从用户获取数据。这也是sql注入的趋势吗?。那么,关于上面的主要问题有什么信息吗?如果
$transid
变量的值可能受到用户的任何影响,那么您就容易受到攻击。关于主要问题,显而易见的答案似乎是,您的查询只返回零行。@AlexHowansky:但如果我从另一个页面运行代码,而不涉及将其作为邮件发送,则记录会完美生成。循环是否有问题,或者是否有更好的方法将从DB获取的表格数据发送到邮件?我猜另一个页面正确设置了
$transid
。添加一些调试语句以验证transid设置是否正确,并添加对
mysqli_num_rows()
(或任何调用)的调用以验证返回的结果是否为非零。