请查看PHPMailer的BODY中包含的代码。系统在$ mail-> Body。=上报告语法错误。 $ row ['updated_by']。 ''; 我已经阅读了PHPMailer的文档,但是却找不到关于在电子邮件的BODY部分插入PHP的更多信息。
$ mail->正文= <<
<table class="table table-striped table-bordered sortable">
<thead>
<tr>
<th>Sales Agent</th>
<th>Company</th>
<th>Contact</th>
<th>Contact Medium</th>
<th>Contact Date</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<?php
include 'database.php';
$pdo = Database::connect();
$yesterday = date('Y-m-d 00:00:00',strtotime("-1 days"));
$sql = "SELECT * FROM `customer_history` WHERE `date_contacted` = '$yesterday'";
$sth = $pdo->prepare($sql);
$sth->execute();
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$mail->Body .= '<tr>';
$mail->Body .= '<td>'. $row['updated_by'] . '</td>';
$mail->Body .= '<td>'. $row['company_name'] . '</td>';
$mail->Body .= '<td>'. $row['first_name'] . '</td>';
$mail->Body .= '<td>'. $row['contacted_by'] . '</td>';
$mail->Body .= '<td>'. $row['date_contacted'] . '</td>';
$mail->Body .= '<td>'. $row['last_result'] . '</td>';
$mail->Body .= '</td>';
$mail->Body .= '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div>
END;
答案 0 :(得分:1)
首先执行db查询,然后将结果添加到正文中。
<?php
$history = '';
include 'database.php';
$pdo = Database::connect();
$yesterday = date('Y-m-d 00:00:00',strtotime("-1 days"));
$sql = "SELECT * FROM `customer_history` WHERE `date_contacted` =
'$yesterday'";
$sth = $pdo->prepare($sql);
$sth->execute();
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$history .= '<tr>';
$history .= '<td>'. $row['updated_by'] . '</td>';
$history .= '<td>'. $row['company_name'] . '</td>';
$history .= '<td>'. $row['first_name'] . '</td>';
$history .= '<td>'. $row['contacted_by'] . '</td>';
$history .= '<td>'. $row['date_contacted'] . '</td>';
$history .= '<td>'. $row['last_result'] . '</td>';
$history .= '</td>';
$history .= '</tr>';
}
Database::disconnect();
// Mail body
$mail->Body = <<<EOF
...
<tbody>
{$history}
</tbody>
...
EOF;