title: php mail form multiple checkbox items
body: <p>I've got a contact form that has multiple checkboxes. I've added [] to the name, but not sure what to do in the PHP. Without the [], I was only getting the first checkbox item to display in the email that was sent. After adding [], I get nada.</p>
  <p>(NOTE: I've tried using similar questions in StackOverflow, but they didn't work for my dilemma.)</p>
  <p>Here's my code (I've truncated the HTML to only show the checkbox area):</p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;form-check&quot;&gt;
    &lt;input type=&quot;checkbox&quot; class=&quot;form-check-input&quot; name=&quot;findout[]&quot; id=&quot;checkbox5&quot; value=&quot;Advertisement&quot;&gt;
    &lt;label for=&quot;findout[]&quot; class=&quot;form-check-label&quot;&gt;Advertisement&lt;/label&gt;
  &lt;/div&gt;
  
  &lt;div class=&quot;form-check&quot;&gt;
    &lt;input type=&quot;checkbox&quot; class=&quot;form-check-input&quot; name=&quot;findout[]&quot; id=&quot;checkbox6&quot; value=&quot;Yard Sign&quot;&gt;
    &lt;label for=&quot;findout[]&quot; class=&quot;form-check-label&quot;&gt;Yard Sign&lt;/label&gt;
  &lt;/div&gt;
  
  &lt;div class=&quot;form-check&quot;&gt;
    &lt;input type=&quot;checkbox&quot; class=&quot;form-check-input&quot; name=&quot;findout[]&quot; id=&quot;checkbox7&quot; value=&quot;Search Engine&quot;&gt;
    &lt;label for=&quot;findout[]&quot; class=&quot;form-check-label&quot;&gt;Search Engine&lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  <pre><code>&lt;?php
      $name = $_POST['name'];
      $email = $_POST['email'];
      $findout = $_POST['findout'];
      $method = $_POST['method'];
      $message = $_POST['message'];
      $subject = $_POST['subject'];
      header('Content-Type: application/json');
      if ($name === ''){
        print json_encode(array('message' =&gt; 'Name cannot be empty', 'code' =&gt; 0));
        exit();
      }
      if ($email === ''){
        print json_encode(array('message' =&gt; 'Email cannot be empty', 'code' =&gt; 0));
        exit();
      } else {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
        print json_encode(array('message' =&gt; 'Email format invalid.', 'code' =&gt; 0));
        exit();
        }
      }
      if ($subject === ''){
        print json_encode(array('message' =&gt; 'Subject cannot be empty', 'code' =&gt; 0));
        exit();
      }
      if ($message === ''){
        print json_encode(array('message' =&gt; 'Message cannot be empty', 'code' =&gt; 0));
        exit();
      }
      
      $content=&quot;From: $name \nEmail: $email \nHow did you find out about us?: $findout \nPreferred way of contact: $method \nMessage: $message&quot;;
      $recipient = &quot;emailaddress@domain.com&quot;;
      $mailheader = &quot;From: $email \r\n&quot;;
      mail($recipient, $subject, $content, $mailheader) or die(&quot;Error!&quot;);
      print json_encode(array('message' =&gt; 'Email successfully sent!', 'code' =&gt; 1));
      exit();
  ?&gt;
  </code></pre>
  <p>Any help is appreciated.</p>
  <p>Mahalo!
  Chris</p>