Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:31:52+00:00 2026-06-14T13:31:52+00:00

i have already research on using the mail() to send to multiple recipient’s but

  • 0

i have already research on using the mail() to send to multiple recipient’s but i just cant get it to work. What im trying to do is, for every order that i have, order 1,2,3, each having their own email addresses, when i change their order status from pending to confirm, the mail() will use that id to refer to the db table and send the email of those 3 orders. But for my case, it mailed just the latest order which is order 3.
This is the form that i use to change the order status.

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

This is the php, using the order id from the form to select the email addresses.

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

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:31:54+00:00Added an answer on June 14, 2026 at 1:31 pm

    You are using the wrong $_POST field to select your email addresses.

    The form generated by the first php file contains a table, with each row containing an input field named 'orderid'. But the field you are really interested in is the select input value of each row. These are all stored in one single array named change in the $_POST array.

    Here’s an example of how $_POST could be initialized to correspond to the select values being returned by the form:

    $_POST['change'] = array('id1' => 'C', 'id2' => 'X' /*, 'id3' => ... */ );
    

    So you need to:

    • get the array returned by the form in $_POST,
    • filter out the entries which aren’t equal to ‘C’,
    • keep the keys of these entries,
    • escape them to sanitize them,

    You should replace the beginning of your php file with the following, which does as explained above.

    This first version doesn’t sanitize the entries:

    <?php
    
    function confirmed($v) { return ($v == 'C'); }
    
    // pick the rows in your form table which have been set as confirmed, and use the keys 
    $orderid = implode(',', array_keys(array_filter($_POST['change'],'confirmed')));
    
    // build SQL statement to select email addresses
    $query3 = "SELECT email FROM ruj3d_virtuemart_order_userinfos WHERE virtuemart_order_id IN (".$orderid.")";
    
    // etc.
    

    This one does sanitization:

    <?php
    
    function confirmed($v) { return ($v == 'C'); }
    
    // pick the rows in your form table which have been set as confirmed, and use the keys 
    $orderid = implode(',', array_map('mysql_real_escape_string', 
                                      array_keys(array_filter($_POST['change'],'confirmed'))));
    
    
    // build SQL statement to select email addresses
    $query3 = "SELECT email FROM ruj3d_virtuemart_order_userinfos WHERE virtuemart_order_id IN (".$orderid.")";
    
    // etc.
    

    See this SO question for the use of BCC with the mail() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to make a case for using Python at my work.
I have been trying to get the result of a lognormal distribution using Scipy
I have already googled and searched stackoverflow but I can find nothing related to
I have already tried multiple ways. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME=YourNameHere;}' Also i've tried
I have already created my application on web socket with ASP.net 4.0. I just
I have already read some posts, but no one helped me with my problem.
We have a problem that we're sure that it's already solved. Our research team
I have a project which our research lab is working, but only a few
I already did a lot of research on this topic and have implemented a
I have already pushed all the changes to the server. Here is the order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.