title: Adding checkboxes to PHP POST email form
body: <p>I'm trying to build a form for wordpress. I've used plugins in the past but I need maximum control for some specific styling. I'm not very good with PHP yet, so am struggling trying to add checkboxes to the script.. I've removed my attempts and left the checkboxes in the html, but not in the PHP - can someone advise me of the best way to make any selected checkboxes visible in the email that is sent? Everything else works at the moment.</p>
  
  <p>the html:</p>
  
  <pre><code>    &lt;form method="post" action="&lt;?php bloginfo('template_directory'); ?&gt;/contact.php"&gt;
  
   &lt;h3&gt;Your Details&lt;/h3&gt;
  
  &lt;div class="formrow"&gt;
      &lt;input type="text" name="Name" maxlength="99" id="fullname" placeholder="Name" /&gt;
      &lt;input type="email" name="Email" maxlength="99"placeholder="Email Address" /&gt;
      &lt;input type="tel" name="Phone" maxlength="25" placeholder="Phone Number" /&gt;
  &lt;/div&gt;
  
  &lt;h3&gt;Project Type&lt;/h3&gt;
  
  &lt;div class="formrow"&gt;
      &lt;fieldset&gt;
          &lt;input type="checkbox" name="project1" value="Web"&gt;
         &lt;label for="type1"&gt;Web&lt;/label&gt;
          &lt;input type="checkbox" name="project2" value="Digital"&gt;
         &lt;label for="type2"&gt;Digital&lt;/label&gt;
          &lt;input type="checkbox" name="project3" value="Consultancy"&gt;
         &lt;label for="type3"&gt;Consultancy&lt;/label&gt; 
      &lt;/fieldset&gt; 
  &lt;/div&gt;
  
   &lt;table align=center&gt; 
   &lt;tr&gt;&lt;td colspan=2&gt;&lt;strong&gt;Contact us using this form:&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; 
   &lt;tr&gt;&lt;td&gt;Department:&lt;/td&gt;&lt;td&gt;&lt;select name="sendto"&gt; &lt;option value="general@mycompany.com"&gt;General&lt;/option&gt; &lt;option value="support@mycompany.com"&gt;Support&lt;/option&gt; &lt;option value="sales@mycompany.com"&gt;Sales&lt;/option&gt; &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; 
  
  
   &lt;tr&gt;&lt;td&gt;Company:&lt;/td&gt;&lt;td&gt;&lt;input size=25 name="Company"&gt;&lt;/td&gt;&lt;/tr&gt; 
  
   &lt;tr&gt;&lt;td&gt;Subscribe to&lt;br&gt; mailing list:&lt;/td&gt;&lt;td&gt;&lt;input type="radio" name="list" value="No"&gt; No Thanks&lt;br&gt; &lt;input type="radio" name="list" value="Yes" checked&gt; Yes, keep me informed&lt;br&gt;&lt;/td&gt;&lt;/tr&gt; 
   &lt;tr&gt;&lt;td colspan=2&gt;Message:&lt;/td&gt;&lt;/tr&gt; 
   &lt;tr&gt;&lt;td colspan=2 align=center&gt;&lt;textarea name="Message" rows=5 cols=35&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt; 
   &lt;tr&gt;&lt;td colspan=2 align=center&gt;&lt;input type=submit name="send" value="Submit"&gt;&lt;/td&gt;&lt;/tr&gt; 
   &lt;tr&gt;&lt;td colspan=2 align=center&gt;&lt;small&gt;A &lt;font color=red&gt;*&lt;/font&gt; indicates a field is required&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt; 
   &lt;/table&gt;
  
   &lt;/form&gt; 
  </code></pre>
  
  <p>the PHP:</p>
  
  <pre><code>&lt;?php 
   $to = $_REQUEST['sendto'] ; 
   $from = $_REQUEST['Email'] ; 
   $name = $_REQUEST['Name'] ; 
   $headers = "From: $from"; 
   $subject = "Web Contact Data"; 
  
   $fields = array(); 
   $fields{"Name"} = "Name"; 
   $fields{"Company"} = "Company"; 
   $fields{"Email"} = "Email"; 
   $fields{"Phone"} = "Phone"; 
   $fields{"list"} = "Mailing List"; 
   $fields{"Message"} = "Message"; 
  
   $body = "We have received the following information:\n\n"; foreach($fields as $a =&gt; $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
  
   $headers2 = "From: noreply@YourCompany.com"; 
   $subject2 = "Thank you for contacting us"; 
   $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
  
   if($from == '') {print "You have not entered an email, please go back and try again";} 
   else { 
   if($name == '') {print "You have not entered a name, please go back and try again";} 
   else { 
   $send = mail($to, $subject, $body, $headers); 
   $send2 = mail($from, $subject2, $autoreply, $headers2); 
   if($send) 
   {print "Success";} 
   else 
   {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } 
   }
  }
   ?&gt; 
  </code></pre>
  
  <p>Thanks! MC</p>