title: Need to be able to send which checboxes are checked to email from a list of checkbox inputs
body: <p>I have about 12 check boxes in a form. I need to know which ones where checked when the data is sent to my email. The code below is my checkbox inputs. Can someone please tell me the php I need to send the value of each checkbox checked to my email? I have searched long and hard for at least 10 hours and I cannot figure it out. I had it working at one point, then I started to get an error message, so starting over with this because I dont even know the code I was using. I just want to know in the email that the php sends me which checkboxes are checked. Here is the part of the form below with the list of checkboxes.</p>
  
  <pre><code>&lt;p&gt;
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['regularMaintenance'] ?&gt; value="regularMaintenance" /&gt;&lt;span class="checkboxlabel"&gt;Regular Maintenance&lt;/span&gt;
  &lt;/p&gt;    
  &lt;p&gt;
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['equipmentRental'] ?&gt; value="equipmentRental" /&gt;&lt;span class="checkboxlabel"&gt;Equipment Rental&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt;    
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['snowManagement'] ?&gt; value="snowManagement" /&gt;&lt;span class="checkboxlabel"&gt;Snow Management&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['windowCare'] ?&gt; value="windowCare" /&gt;&lt;span class="checkboxlabel"&gt;Window Care&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['aeration'] ?&gt; value="aeration" /&gt;&lt;span class="checkboxlabel"&gt;Aeration&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['gutterCleaning'] ?&gt; value="gutterCleaning" /&gt;&lt;span class="checkboxlabel"&gt;Gutter Cleaning&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['powerRake'] ?&gt; value="powerRake" /&gt;&lt;span class="checkboxlabel"&gt;PowerRake&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['sodding'] ?&gt; value="sodding" /&gt;&lt;span class="checkboxlabel"&gt;Sodding&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['treeSpraying'] ?&gt; value="treeSpraying" /&gt;&lt;span class="checkboxlabel"&gt;Tree Spraying&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['springCleanup'] ?&gt; value="springCleanup" /&gt;&lt;span class="checkboxlabel"&gt;Spring Clean Up&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['fallCleanup'] ?&gt; value="fallCleanup" /&gt;&lt;span class="checkboxlabel"&gt;Fall Clean Up&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['fertilize'] ?&gt; value="fertilize" /&gt;&lt;span class="checkboxlabel"&gt;Fertilizing&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['sprinklerwinterization'] ?&gt; value="sprinklerwinterization" /&gt;&lt;span class="checkboxlabel"&gt;Sprinkler Winterization&lt;/span&gt;
  &lt;/p&gt;  
  &lt;p&gt; 
  &lt;input type="checkbox" name="service[]" &lt;?php echo $selected['other'] ?&gt; value="other" /&gt;&lt;span class="checkboxlabel"&gt;Other&lt;/span&gt;
  &lt;/p&gt;   enter code here
  </code></pre>
  
  <p>My form's action code is: action="</p>
  
  <p>...and here is my php validation and send to emal code. I dont know anythiing about php, and I forgot where to add the code that you told me. I have one part that says foreach 
           ($_POST['service'] as $selectedService)
              $selected[$selectedService] = "checked";
  which keeps the checkboxes checked when the form is sumitted and there is an error so it returns back to the form. This part doesnt give me an error though, but if I use in my<br>
       `$message:
        Services Selected: " . $selectedService . " 
  and they check more than one box, I only get one of the boxes they checked. </p>
  
  <p>so here is my php code. I m sure that I am placing something somewhere wrong or something.</p>
  
  <pre><code>&lt;?php
  
  // define variables and set to empty values
  $nameErr = $emailErr = $email2Err = $commentsErr = "";
  $name = $email = $email2 = $comments = "";
  
  if ($_SERVER["REQUEST_METHOD"] == "POST")
  {
  
     if (empty($_POST["name"]))
       {$nameErr = "Name is required";}
     else
       {$name = test_input($_POST["name"]);
        // check if name only contains letters and whitespace
      if (!preg_match("/^[a-zA-Z ]*$/",$name))
        {
        $nameErr = "Only letters and white space allowed"; 
        }
      }
  
  
     if (empty($_POST["email"]))
       {$emailErr = "Email is required";}
     else
       {$email = test_input($_POST["email"]);
       // check if e-mail address syntax is valid
      if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
        {
        $emailErr = "Invalid email format"; 
        }
      }
  
     if (empty($_POST["email2"]))
       {$email2Err = "It is required to re-enter your email.";}
     else
       {$email2 = test_input($_POST["email2"]);
       // check if e-mail address syntax is valid
      if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email2))
        {
        $email2Err = "Invalid email format"; 
        }
      }
  
      if (empty($_POST["comments"]))
       {$commentsErr = "A comment is required.";}
     else
       {$comments = test_input($_POST["comments"]);
        if (preg_match("#^[a-zA-Z0-9 \.,\?_/'!£\$%&amp;*()+=\r\n-]+$#", $comments)) { 
          // Everything ok. Do nothing and continue 
      } else { 
          $commentsErr = "Message is not in correct format.&lt;br&gt;You can use a-z A-Z 0-9 . , ? _ / ' ! £ $ % * () + = - Only";  
        }
      }
       if (isset($_POST['service']))
      {
          foreach ($_POST['service'] as $selectedService)
              $selected[$selectedService] = "checked";
      }
  
  }
  
  function test_input($data)
  {
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
  }
  
  if (empty($errors)) { 
    $from = "From: Our Site!"; //Site name
    // Change this to your email address you want to form sent to
    $to = "jasonriseden@yahoo.com"; 
    $subject = "Mr Green Website | Comment from " . $name . "";
  
    $message = "Message from " . $name . " 
    Email: " . $email . " 
    Comments: " . $comments . "";
    mail($to,$subject,$message,$from);
  
    }
  ?&gt;
  </code></pre>