php - Send email array (foreach) -
i need send array of products email php i'm getting trouble "foreach".
this 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 jquery code grab data (i'm working on wordpress , couldn't find way $_server['php_self']...
//jquery var productval = jquery(".product").val(); var boxesval = jquery(".boxesinput").val();  jquery.post("sendemail.php",             { boxes: boxesval, product: productval } ); this sendemail.php file
//sendemail.php  $producto = $_post['product']; $boxes = $_post['boxes'];  $body = "order details \n" ; this trouble , foreach:
foreach($producto $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); 
as serj points out, need serialize form data in order php understand it. better use
$.post("sendmail.php", $("form").serialize()); to send form data. problem declare variable
$boxes = $_post['boxes']; but foreach tries access $cajas[$id]? if change foreach loop to
foreach($producto $id => $row ) {  $body .= "producto: " .  $producto[$id]  . "\n";  $body .= "cajas: " .  $boxes[$id]  . "\n";  }  it should work. note form elements suitable generate arrays take single values.
Comments
Post a Comment