0

当我更新订单状态以通知客户时,我只想使用 mail() 向收件人发送多封电子邮件。(我使用我自己的电子邮件作为测试,从 1 到 10 的每个订单都是我的电子邮件。) 所以我想收到不止一封给自己的电子邮件。但是当我这样做时,我只收到了一封电子邮件并且在里面在“收件人”部分发送电子邮件,它会显示我的电子邮件 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">&nbsp;</th>
<th scope="col">&nbsp;</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">&nbsp;</th>
<th width="103" scope="col">&nbsp;</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>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<hr>
<table width="500" height="227" border="0">
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Subtotal:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Tax:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Shipping:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Discount:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th width="40" height="43" scope="col">&nbsp;</th>
<th width="278" scope="col">&nbsp;</th>
<th width="68" scope="col">Grand Total:</th>
<th width="96" scope="col">&nbsp;</th>
</tr>
</table>
<p align="right">&nbsp;</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);


?>
4

1 回答 1

1

您需要将编写和发送邮件的代码移到

while ($row3 = mysqli_fetch_array($result3)) {
...
}

循环,而不是制作所有地址的数组。

于 2012-11-23T06:14:07.780 回答