2012-11-23 4 views
0

고객에게 알리기 위해 주문 상태를 업데이트 할 때 mail()을 사용하여 수신자에게 여러 이메일을 보내려합니다. (내 자신의 이메일을 테스트 용으로 사용하고 있으며, 1에서 10까지의 주문은 모두 내 이메일입니다.) 그래서 나는 둘 이상의 이메일을 자신에게 receieved라고 가정합니다 .. 하지만 내가 그랬을 때, 이메일을 보내고 "to"섹션에서 그 이메일을 열면 내 이메일이 10 번 표시됩니다 !! ([email protected], [email protected], [email protected] ...)여러 수신자에게 메일 보내기 (계속)

이것은 내 양식입니다.

<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); 


?> 
+0

'$ to' 문자열을 올바르게 작성하고 있습니까? 그것을 검증하기 위해'mail()'을 호출하기 전에 인쇄하십시오. –

+0

나는 var_dump ($ to)를 수행했습니다. 이것은 다음과 같이 보여줍니다. string (51) "[email protected], [email protected]" –

답변

1

는 대신 모든 주소의 배열을 만드는, 작곡 및

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

루프 내에서 메일을 보내는 코드를 이동해야합니다.

+0

동일한 전자 메일을 여러 번 동일한 전자 메일 주소로 보낼 수있는 방법이 있습니까? –

+0

'mail() '을 여러 번 호출하십시오. – Barmar

+0

괜찮습니까? 그래서 그냥 복사하여 10 번 rite 메일() 붙여 넣기? –

관련 문제