title: PHP Contact form with checkboxes
body: <p>I'm having a terrible time trying to get my contact form to work.  I have almost no php experience.  I am trying to make this form e-mail to myself but have no idea what I am doing basically.</p>
  
  <p>I need it to e-mail a copy of the form to my e-mail and also make sure the checkboxes show which boxes were clicked.</p>
  
  <p>If anyone could help I would appreciate it.</p>
  
  <p>Here is my html</p>
  
  <pre><code>&lt;form name="htmlform" method="post" action="send_form_email.php"&gt;
  &lt;table width="561"&gt;
  &lt;tr&gt;
   &lt;td width="212" align="right" valign="top"&gt;
    &lt;label for="name"&gt;*Name&lt;/label&gt;
   &lt;/td&gt;
   &lt;td width="337" valign="top"&gt;
    &lt;input  type="text" name="name" maxlength="150" size="50"&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td valign="top" align="right"&gt;
    &lt;label for="company"&gt;*Company&lt;/label&gt;
   &lt;/td&gt;
   &lt;td width="337" valign="top"&gt;
    &lt;input  type="text" name="name" maxlength="150" size="50"&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td valign="top" align="right"&gt;
    &lt;label for="telephone"&gt;Phone&lt;/label&gt;
   &lt;/td&gt;
   &lt;td valign="top"&gt;
    &lt;input  type="text" name="telephone" maxlength="150" size="50"&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td valign="top" align="right"&gt;
    &lt;label for="email"&gt;*Email Address&lt;/label&gt;
   &lt;/td&gt;
   &lt;td valign="top"&gt;
    &lt;input  type="text" name="email" maxlength="180" size="50"&gt;
   &lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td valign="top" align="right"&gt;
    &lt;label for="services"&gt;*Current Services&lt;br /&gt;
  (check all that apply)&lt;/label&gt;
   &lt;/td&gt;
   &lt;td valign="top"&gt;
  &lt;input type="checkbox" name="services[]" value="none" /&gt;&amp;nbsp;None&lt;br /&gt;
  
  &lt;input type="checkbox" name="services[]" value="coffee" /&gt;&amp;nbsp;Coffee&lt;br /&gt;
  
  &lt;input type="checkbox" name="services[]" value="vending" /&gt;&amp;nbsp;Vending&lt;br /&gt;
  
  &lt;input type="checkbox" name="services[]" value="watercoolers" /&gt;&amp;nbsp;Water Coolers&lt;br /&gt;
  
  &lt;input type="checkbox" name="services[]" value="cafeteria" /&gt;&amp;nbsp;Cafeteria&lt;br /&gt;
  
   &lt;/td&gt;
   &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td valign="top" align="right"&gt;
    &lt;label for="comments"&gt;*Comments&lt;/label&gt;
   &lt;/td&gt;
   &lt;td valign="top"&gt;
    &lt;textarea  name="comments" maxlength="1000" cols="40" rows="6"&gt;&lt;/textarea&gt;
   &lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td colspan="2" style="text-align:center"&gt;
    &lt;center&gt;&lt;input type="submit" value="Submit Form"&gt;&lt;/center&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my php.</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['email'])) {
  
      // EDIT THE 2 LINES BELOW AS REQUIRED
      $email_to = "michael@mrugenus.com";
      $email_subject = "Contact form";
  
      $email_message = "Form details below.\n\n";
  
      function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
      }
  
      $email_message .= "Name: ".clean_string($name)."\n";
      $email_message .= "Email: ".clean_string($email_from)."\n";
      $email_message .= "Telephone: ".clean_string($telephone)."\n";
      $email_message .= "Services: ".implode(",", $_POST['services'])."\n";
      $email_message .= "Comments: ".clean_string($comments)."\n";
  
  
  // create email headers
  $headers = 'From: '.$email_from."\r\n".
  'Reply-To: '.$email_from."\r\n" .
  'X-Mailer: PHP/' . phpversion();
  @mail($email_to, $email_subject, $email_message, $headers); 
  ?&gt;
  
  &lt;!-- include your own success html here --&gt;
  &lt;center&gt;
  &lt;img src="images/logo.png" /&gt;
    &lt;br&gt;
    &lt;br&gt;
    Thank you for contacting us.  We will be in touch.&lt;br&gt;
  &lt;br&gt;
   &lt;a href="index.html"&gt;HOME&lt;/a&gt;&lt;/center&gt;
  
  &lt;?php
  }
  ?&gt;
  </code></pre>