我已经研究过使用 mail() 发送给多个收件人,但我无法让它工作。我想要做的是,对于我拥有的每个订单,订单 1、2、3,每个都有自己的电子邮件地址,当我将他们的订单状态从待定更改为确认时,mail() 将使用该 ID 来引用db 表并发送这 3 个订单的电子邮件。但就我而言,它只邮寄了最新的订单,即订单 3。这是我用来更改订单状态的表格。
<form action="results-action" method="post" enctype="multipart/form-data">
<fieldset>
<table id ="table_id" class="display">
<thead>
<tr><td><h2>Pending Order</h2></td></tr>
<tr>
<th scope="col">Order ID</th>
<th scope="col"> </th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Product Name</th>
<th scope="col">Produt Quantity</th>
<th scope="col">Price</th>
<th scope="col">Order status</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" value='<?=$row['virtuemart_order_id']?>' name="orderid" id="virtuemart_order_id"></td>
<td><input type="hidden" value='<?=$row['virtuemart_product_id']?>' name="productid" id="virtuemart_product_id"></td>
<td><?=$row['first_name']?></td>
<td><?=$row['address_1']?></td>
<td><?=$row['order_item_name']?></td>
<td><?=$row['product_quantity']?></td>
<td><?=$row['product_final_price'] ?></td>
<td><select name='change[<?=$row['virtuemart_order_id']?>]'>
<option value='C'> Confirmed</option>
<option value='X'> Cancelled</option></select></td>
</tr>
<?php
}
?>
</tbody>
</table>
</fieldset>
<fieldset>
<table>
<tr>
<td><input type="submit" value="Update status" name="update status"> </td>
</tr>
</table>
</fieldset>
</form>
这是 php,使用表单中的订单 ID 来选择电子邮件地址。
<?php
$orderid = $_POST['orderid'];
// build SQL statement to select email addresses
$query3 = "SELECT email from ruj3d_virtuemart_order_userinfos where virtuemart_order_id = '$orderid'";
// execute SQL statement
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
$subject = "Order confirmed by Home and decor";
$message = "Hello! This is a message to inform that your order has been confirmed";
$from = "107496@myrp.edu.sg";
$headers = "From: $from";
while($row3 = mysqli_fetch_array($result3)){
$addresses[] = $row3['email'];
}
$to = implode(",", $addresses);
mail($to, $subject, $message, $headers);
?>