title: Pass multiple checkbox values to PHP Mail
body: <p>I'm trying to pass checkbox values to PHP but the interests field shows up blank. I need to display all the interests values checked. And send out an email. I've included all three parts. All the other fields are displaying properly.</p>
  <p>Here's the HTML part</p>
  <pre><code>                            &lt;form id=&quot;register-form&quot; class=&quot;register-form register&quot; action=&quot;php/register.php&quot; method=&quot;post&quot;&gt;
                                  
                      
                                  &lt;input class=&quot;register-input name-input white-input&quot; required=&quot;&quot; name=&quot;register_names&quot; placeholder=&quot;Full Name*&quot; type=&quot;text&quot;&gt;
                                  
                                  &lt;input class=&quot;register-input name-email white-input&quot; required=&quot;&quot; name=&quot;register_phone&quot; placeholder=&quot;Phone*&quot; type=&quot;text&quot;&gt;
                              
                                  &lt;input class=&quot;register-input name-email white-input&quot; required=&quot;&quot; name=&quot;register_email&quot; placeholder=&quot;Email Adress*&quot; type=&quot;email&quot;&gt;
                                  
                                  &lt;input class=&quot;register-input name-email white-input&quot;  name=&quot;register_company&quot; placeholder=&quot;Company&quot; type=&quot;text&quot;&gt;
                                  
                                  &lt;table cellspacing=&quot;8&quot; cellpadding=&quot;0&quot;&gt;
                                      &lt;tr&gt;
                                          &lt;td&gt;&lt;input class=&quot;register-input name-email white-input&quot; name=&quot;register_city&quot; placeholder=&quot;City&quot; type=&quot;text&quot;&gt;&lt;/td&gt;
                                          &lt;td width=&quot;10&quot;&gt;&amp;nbsp;&lt;/td&gt;
                                          &lt;td&gt;&lt;input class=&quot;register-input name-email white-input&quot; name=&quot;register_zip&quot; placeholder=&quot;Zip&quot; type=&quot;text&quot;&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                  &lt;/table&gt;
                                  
                                  &lt;table cellspacing=&quot;8&quot; cellpadding=&quot;8&quot;&gt;
                                      
                                      &lt;tr&gt;&lt;fieldset&gt;
                                          &lt;td&gt;
                                              &lt;input type=&quot;checkbox&quot; name=&quot;interests[]&quot; value=&quot;Practice&quot; /&gt;&amp;nbsp;&amp;nbsp;Practice&lt;br /&gt;
                                              &lt;input type=&quot;checkbox&quot; name=&quot;interests[]&quot; value=&quot;Training&quot; /&gt;&amp;nbsp;&amp;nbsp;Training&lt;br /&gt;
                                              &lt;input type=&quot;checkbox&quot; name=&quot;interests[]&quot; value=&quot;Workout&quot; /&gt;&amp;nbsp;&amp;nbsp;Workout&lt;br /&gt;
                                              
                                          &lt;/td&gt;
                                          &lt;/fieldset&gt;
                                      &lt;/tr&gt;
                                      
                                  &lt;/table&gt;
                                 
                                  &lt;input value=&quot;Submit Request&quot; class=&quot;register-submit&quot; type=&quot;submit&quot;&gt;
                                      
                              &lt;/form&gt;
  </code></pre>
  <p>Here's the JQuery part for validation</p>
  <pre><code>    $('#register-form').each( function(){
          var form = $(this);
          //form.validate();
          form.submit(function(e) {
              if (!e.isDefaultPrevented()) {
                  jQuery.post(this.action,{
                      'names':$('input[name=&quot;register_names&quot;]').val(),
                      'email':$('input[name=&quot;register_email&quot;]').val(),
                      'phone':$('input[name=&quot;register_phone&quot;]').val(),
                      'company':$('input[name=&quot;register_company&quot;]').val(),
                      'city':$('input[name=&quot;register_city&quot;]').val(),
                      'zip':$('input[name=&quot;register_zip&quot;]').val(),
                      'interests':$('checkbox[name=&quot;interests&quot;]').val(),
                  },function(data){
                      form.fadeOut('fast', function() {
                          $(this).siblings('p.register_success_box').show();
                      });
                  });
                  e.preventDefault();
              }
          });
      })
  </code></pre>
  <p>Lastly, here's the PHP part to generate the email</p>
  <pre><code>&lt;?php
  
  $field_first_name = $_POST['names'];
  
  $field_email = $_POST['email'];
  
  $field_phone = $_POST['phone'];
  
  $field_company = $_POST['company'];
  
  $field_city = $_POST['city'];
  
  $field_zip = $_POST['zip'];
  
  $interests = (is_array($_POST['interests']) ? $_POST['interests'] : []);
  $interests = (count($interests) &gt; 0 ? implode(',', $interests) : 'none');
  
  
  $mail_to = 'to@email.com';
  
  $subject = 'Message from a landing page visitor '.$field_first_name;
  
  $body_message = 'From: '.$field_first_name.&quot;\n&quot;;
  
  $body_message .= 'E-mail: '.$field_email.&quot;\n&quot;;
  
  $body_message .= 'Phone: '.$field_phone.&quot;\n&quot;;
  
  $body_message .= 'Company: '.$field_company.&quot;\n&quot;;
  
  $body_message .= 'City: '.$field_city.&quot;\n&quot;;
  
  $body_message .= 'Zip: '.$field_zip.&quot;\n&quot;;
  
  $body_message .= 'Interests:  '.trim($interests).' ';
  
  
  $headers = 'From: '.$field_email.&quot;\r\n&quot;;
  
  $headers .= 'Reply-To: '.$field_email.&quot;\r\n&quot;;
  
  $mail_status = mail($mail_to, $subject, $body_message, $headers);
  
  
  if ($mail_status) { ?&gt;
      &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
  
  
  ----------
  
  
          window.location = 'index.html';
      &lt;/script&gt;
  &lt;?php
  }
  else { ?&gt;
      &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
          window.location = 'index.html';
      &lt;/script&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>