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();
}
}
?>