title: How to send a copy of email to senders address in php contact form
body: <p>I have a contact form in my website. I need users to send messages to my email, and it does so. I also have a checkbox, which when checked, the users will have the message to the email indicated on the email textbox. My code sends it only to my email, but it doesn't send a copy when the checkbox is checked.</p>
  
  <p><em><strong>Contact.html</em></strong></p>
  
  <pre><code>&lt;input type="checkbox" name="sendcopy" value="Yes" checked/&gt;Copy this message to your mail
  </code></pre>
  
  <p><em><strong>Sendmail.php:</em></strong></p>
  
  <pre><code>$messagebody="Name: ".$name."".PHP_EOL;
  $messagebody.="email: ".$email."".PHP_EOL;
  $messagebody.="website: ".$website."".PHP_EOL;
  $messagebody.="message: ".nl2br($message)."".PHP_EOL;
  
  mail($to,$subject,$messagebody,$headers)or die("The message failed to send");  
  
  if(isset($_POST["sendcopy"]) &amp;&amp; $_POST["sendcopy"]=="checked"){
  mail($email,$subject,$messagebody,$headers)or die("The message failed to send a copy") 
      }
  </code></pre>