ds15812330851 2019-07-07 10:18
浏览 100
已采纳

在通过phpmailer发送变量之前将循环等于变量

I have a checkbox form which is sent to mail.php to be mailed. The selected items should be sent via mail. I have a query to output selected items. In mail body; to echo all selected items which pulled from database, i need to equal the while loop to a variable. But i can not manage it to equal.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

include 'nedmin/netting/database.php';

if (isset($_POST['sendmail'])) {

$city=array_keys($_POST['cities']);

$cities=implode(",",$city);


$query = $db->prepare("SELECT * FROM semt WHERE semt_id IN('".$cities."')");

$query->execute();

while ($statement = $query->fetch(PDO::FETCH_ASSOC)) {

?>
   <td><?php echo $statement["city_name"]?></td>

<?php }


$mail = new PHPMailer;

try {
   /* SMTP parameters. */
   $mail->isSMTP();
   $mail->SMTPKeepAlive = TRUE;   
   $mail->SMTPAuth = TRUE;
   $mail->SMTPSecure = 'tls';

   ...
   ...
   ...
   $mail->isHTML(TRUE);
   $mail->Subject = "Subject";
   $mail->Body = "Selected cities: $......";

   $mail->send();
}
catch (Exception $e)
{
   echo $e->errorMessage();
}
catch (\Exception $e)
{
   echo $e->getMessage();
}
}
?>
  • 写回答

2条回答 默认 最新

  • douweng9427 2019-07-07 10:30
    关注
    $citiesName = [];
    
    while ($statement = $query->fetch(PDO::FETCH_ASSOC)) { ?>
        <td><?php echo $statement["city_name"]?></td>
        <?php $citiesName[] = $statement["city_name"]?>
    <?php }
    
    //code ...
    $mail->Body = "Selected cities: " . implode(',', $citiesName);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 基于8255的交通灯设计
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力
  • ¥15 c语言题目:成绩管理系统