注文ステータスを更新して顧客に通知するときに、mail()を使用して複数の電子メールを受信者に送信したいだけです。(私は自分の電子メールをテストとして使用しており、1から10までの各注文が私の電子メールです。) したがって、自分自身に複数の電子メールを受信したと仮定します。 「to」セクションにメールを送信すると、私のメールが10回表示されます。(ahmadxxx @ hotmail.com、ahmadxxx @ hotmail.com、ahmadxxx @ hotmail.com ...)
これが私のフォームです。
<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">Order Number</th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Payment Method</th>
<th scope="col">Order Date</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><?=$row['order_number']?></td>
<td><?=$row['first_name']?></td>
<td><?=$row['address_1']?></td>
<td><?=$row['payment_element']?></td>
<td><?=$row['created_on']?></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
//filtering confirmed orders
function confirmed($v){return($v =='C');}
// pick the rows in your form table which have been set as confirmed, and use the keys
$id = implode(',', array_keys(array_filter($_POST['change'],'confirmed')));
// build SQL statement mail
$query3 = "SELECT * from ruj3d_virtuemart_order_userinfos where virtuemart_order_id IN (".$id.")";
// execute SQL statement
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
while($row3 = mysqli_fetch_array($result3)){
$addresses[]=$row3['email'];
}
$to = implode(", ",$addresses);
$subject = "Order confirmed by Home and decor";
// message
$message = '
<html>
<body>
<table width="500" height="215" border="0">
<tr>
<th width="238" height="211" scope="col"><h1 align="left">Order # 1234</h1></p></th>
<th width="10" scope="col"></th>
<th width="243" scope="col"><p><img src="file:///D|/Programs/xampp/htdocs/images/sitelogo.PNG" width="224" height="68" align="right"></p></th>
</tr>
</table>
<table width="500" height="215" border="0">
<tr>
<th width="181" height="211" scope="col"><p align="left">Ship To:</p>
<p align="left">Customer name</p>
<p align="left">Blk 123</p>
<p align="left">Singapore, 123123</p></th>
<th width="80" scope="col"></th>
<th width="40" scope="col"></th>
<th width="181" scope="col"><p align="left"></p>
<p align="right">Bill To:</p>
<p align="right">Customer name</p>
<p align="right">Blk 123</p>
<p align="right">Singapore, 123123</p>
</th>
</tr>
</table>
<table width="500" height="94" border="0">
<tr>
<th height="43" scope="col"><div align="left">Order Date:</div></th>
<th scope="col"> </th>
<th scope="col"> </th>
<th scope="col"><div align="right">Shipping Method:</div></th>
</tr>
<tr>
<th width="126" height="43" scope="col"><div align="left">1/11/13</div></th>
<th width="433" scope="col"> </th>
<th width="103" scope="col"> </th>
<th width="156" scope="col"><div align="right">BEAST!</div></th>
</tr>
</table>
<table width="500" height="88" border="1">
<tr>
<th width="48" scope="col">Item</th>
<th width="264" scope="col">Product Name</th>
<th width="68" scope="col">Quantity</th>
<th width="92" scope="col">Price</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<hr>
<table width="500" height="227" border="0">
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Subtotal:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Tax:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Shipping:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Discount:</th>
<th scope="col"> </th>
</tr>
<tr>
<th width="40" height="43" scope="col"> </th>
<th width="278" scope="col"> </th>
<th width="68" scope="col">Grand Total:</th>
<th width="96" scope="col"> </th>
</tr>
</table>
<p align="right"> </p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
?>