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 6187443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:03:32+00:00 2026-05-24T02:03:32+00:00

I need to send an array of products by email with PHP but I’m

  • 0

I need to send an array of products by email with PHP but I’m getting trouble with a “foreach“.

This is my code:

//Form
<form action="" method="post">
    <select name="product[]" class="product" >
      <option value="product1">product1</option>
      <option value="product2">product2</option>
      <option value="product3">product3</option>
    </select>
    <input type="text" name="boxes[]" value="Boxes:" class="boxesInput" size="20">
</form>

This is the jQuery code to grab the data (I’m working on wordpress and couldn’t find a way to do with $_SERVER[‘PHP_SELF’]‎…

//jQuery
var productVal = jQuery(".product").val();
var boxesVal = jQuery(".boxesInput").val();

jQuery.post("sendemail.php",
            { boxes: boxesVal, product: productVal } );

This is the sendemail.php file

//sendemail.php

$producto = $_POST['product'];
$boxes = $_POST['boxes'];

$body = "Order Details \n" ;

This is the trouble , the foreach:

foreach($producto as $id => $row )
{
 $body .= "Product: " .  $producto[$id]  . "\n";
 $body .= "Boxes: " .  $boxes[$id]  . "\n"; 
} 

$mailTo = 'my@email.com'; 
$subject = "Quotes Form";
$headers = 'From: <'.$mailTo.'> ' . "\r\n" . 'Reply-To: ' . $mailTo;
mail($mailTo, $subject, $body, $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-05-24T02:03:32+00:00Added an answer on May 24, 2026 at 2:03 am

    As Serj points out, you need to serialize the form data in order for php to understand it. Probably better to use

    $.post("sendmail.php", $("form").serialize());
    

    to send your form data. Another problem is that you declare the variable

    $boxes = $_POST['boxes'];
    

    but the foreach tries to access $cajas[$id]? if you change your foreach loop to

    foreach($producto as $id => $row )
    {
     $body .= "Producto: " .  $producto[$id]  . "\n";
     $body .= "Cajas: " .  $boxes[$id]  . "\n"; 
    } 
    

    it should work. Note that your form elements are actually suitable to generate arrays as they only take single values.

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

Sidebar

Related Questions

i have array in php, and i need work with this array in jQuery.
in my app i need to send an javascript Array object to php script
i need to send raw multipart data with a php POST but without an
I need to send an array of checkbox values to a form on submit.
I'm trying to load an array in my javascript. I need to send this
I need to send an array to a server but I cannot seem to
I need to send byte[] array using WCF services and I care about message
I need to send hundreds of newsletters, but would like to check first if
We need to send email which contains Pound (currency) symbols in ColdFusion. Before sending
how to send array through url in PHP? I have an array of product

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.