title: send AJAX json array mail with PHP mailer
body: <p>I am trying to send a php form mailer with data array using Json and AJAX, but for some reason, the mail is sent without the data...
  (I tested the jason string and validated it to make sure it contains data)</p>
  
  <p>Here is the code I have:</p>
  
  <p>json:</p>
  
  <pre><code> function submitFields() {
      form_elements = [];
      $('.dataField').each(function () { 
          frm_name = $(this).attr('name'); 
          frm_qty = $(this).val();
          frm_price = $(this).data('price');
          current_frm_obj = {name:frm_name, qty:frm_qty, price:frm_price};
          form_elements.push(current_frm_obj);
      });
  
      $.ajax({
          type: "POST", 
          url: "mailer.php",
          data: { result:JSON.stringify(form_elements) },
          success : function(response) {
              console.log(form_elements);
              alert(response);
          }    
      });
  }
  </code></pre>
  
  <p>PHP mailer:</p>
  
  <pre><code>$data = $_POST["result"];
  $decoded = json_decode($data);
  $errors = '';
  $myemail = 'office@studiodeshe.com';
  
  $to = $myemail; 
  $email_subject = "Form info";
  $email_body = 
  $decoded = json_decode($data);
  foreach ($decoded as $curr_element) {
      $fieldName = $curr_element-&gt;name;
      $fieldQty = $curr_element-&gt;qty;
      $fieldPrice = $curr_element-&gt;price;
  
      if ( $fieldQty != 0 ) {
          $fieldName .': &lt;br /&gt;' .  $fieldQty;
          if ($fieldPrice != 0) {
              'Qty: ' . $fieldQty . '&lt;br /&gt;';
              'Price: ' . $fieldPrice . '&lt;br /&gt;';
              'Total: ' . ($fieldPrice*$fieldQty) . '&lt;br /&gt;&lt;br /&gt;';
              }
      }
  }
  
  $headers = "From: studiodeshe &lt;office@studiodeshe.com&gt; \n"; 
  $headers .= 'Content-type: text/html; charset=utf-8'; 
  
  mail($to,$email_subject,$email_body,$headers);
  header('Location: ty.html');
  </code></pre>
  
  <p>I am guessing that there is some problem with the way I am trying to decode the data in the mailer but can't find a solution...</p>