SQL Table [orders]
| orderId | dueDate | emailAddress |
| ------- | ---------- | -------------- |
| 1010101 | 10/11/2021 | joe@gmail.com |
| 1010102 | 10/11/2021 | joe@gmail.com |
| 1010103 | 10/11/2021 | joe@gmail.com |
| 1010104 | 10/11/2021 | john@gmail.com |
| 1010105 | 10/11/2021 | john@gmail.com |
| 1010106 | 10/11/2021 | john@gmail.com |
PHP Script
$query = "SELECT * FROM orders";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($result)) {
$order = $row['orderId'];
$to = $row['emailAddress'];
$sub = "Payment Due Reminder";
$body = "Due reminder message with order ID $order";
mail($to, $sub, $body);
}
My Requirement
Now I want to send only one email listing the three order IDs rather than sending three emails to the same recipient. Is there a way to achieve it?