while 循环和 php-mailer
while loop and php-mailer
我使用 phpmailer 在操作完成后发送电子邮件。现在这是我的 phpmailer 代码的最后一部分
$mail->Subject = 'Nuovo Ordine';
$mail->Body = $ordine_iniz.$ordine_cent.$ordine_fine;
$mail->AltBody = '';
这是我想插入正文的变量
$ordine_iniz='
Nuovo Ordine Spiaggia dal Sig./Sig.ra '.$nome.' '.$cognome.'<br />
<table style="text-align:center;" cellpadding="5">
<thead style="background-color:#EBE9E9">
<tr>
<th scope="col">#</th>
<th scope="col">Prodotto</th>
<th scope="col">Quantità</th>
</tr>
</thead>
<tbody style="background-color:F5FFFF">';
$ordine_fine='</tbody></table>';
$i=0;
$query = "SELECT * FROM table";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$ordine_cent='<tr><td>'.$i.'</td><td>'.$row["prodotto"].'</td
<td>'.$row["quantita"].'</td></tr>';
$i++;}
现在的问题是邮件发送有效,但邮件中的 table 只给我一行 table 'table' 的最后结果。我想要所有行
我该如何解决?
而不是
$ordine_cent=
做
$ordine_cent .=
as =
将覆盖旧值而不是附加到它。
您需要追加,每次都重新分配 $ordine_cent
。在while循环之前,初始化$ordine_cent = ''
什么的。之后在 while 循环中执行此操作:
$ordine_cent .= '<tr><td>'.$i.'</td><td>'.$row["prodotto"].'</td<td>'.$row["quantita"].'</td></tr>';
我使用 phpmailer 在操作完成后发送电子邮件。现在这是我的 phpmailer 代码的最后一部分
$mail->Subject = 'Nuovo Ordine';
$mail->Body = $ordine_iniz.$ordine_cent.$ordine_fine;
$mail->AltBody = '';
这是我想插入正文的变量
$ordine_iniz='
Nuovo Ordine Spiaggia dal Sig./Sig.ra '.$nome.' '.$cognome.'<br />
<table style="text-align:center;" cellpadding="5">
<thead style="background-color:#EBE9E9">
<tr>
<th scope="col">#</th>
<th scope="col">Prodotto</th>
<th scope="col">Quantità</th>
</tr>
</thead>
<tbody style="background-color:F5FFFF">';
$ordine_fine='</tbody></table>';
$i=0;
$query = "SELECT * FROM table";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$ordine_cent='<tr><td>'.$i.'</td><td>'.$row["prodotto"].'</td
<td>'.$row["quantita"].'</td></tr>';
$i++;}
现在的问题是邮件发送有效,但邮件中的 table 只给我一行 table 'table' 的最后结果。我想要所有行
我该如何解决?
而不是
$ordine_cent=
做
$ordine_cent .=
as =
将覆盖旧值而不是附加到它。
您需要追加,每次都重新分配 $ordine_cent
。在while循环之前,初始化$ordine_cent = ''
什么的。之后在 while 循环中执行此操作:
$ordine_cent .= '<tr><td>'.$i.'</td><td>'.$row["prodotto"].'</td<td>'.$row["quantita"].'</td></tr>';