title: Contact Form returns message to sender
body: <p>I have a site that I started recently, and the contact form seems to be broken. What happens is, the email that the sender will submit will actually receive the message the sender tries to sent. Instead of the designated receiver receiving the email.</p>
  
  <p>There are 3 files in the contact folder.</p>
  
  <p><strong>freecontactformvalidation.js</strong></p>
  
  <pre><code>    function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;}
  return true;}
  function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;}
  return true;}
  function $$(id){if(!has_id(id)&amp;&amp;!has_name(id)){alert("Field "+id+" does not exist!\n Form validation configuration error.");return false;}
  if(has_id(id)){return document.getElementById(id).value;}else{return;}}
  function $val(id){return document.getElementById(id);}
  function trim(id){$val(id).value=$val(id).value.replace(/^\s+/,'').replace(/\s+$/,'');}
  var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\n\n';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i&lt;required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' must be supplied\n';if(has_id(required.field[i][0])&amp;&amp;to_focus.length===0){to_focus=required.field[i][0];}
  tmp=false;}}
  if(!tmp){alert(error_message);}
  if(to_focus.length&gt;0){document.getElementById(to_focus).focus();}
  return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length&lt;1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;if($$(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length&gt;0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};
  </code></pre>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>    &lt;?php include("../config.php"); ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Contact  &lt;?php echo $meta_title; ?&gt;&lt;/title&gt;
  &lt;meta name="description" content="&lt;?php echo $meta_desc; ?&gt;"&gt;
  &lt;meta name="keywords" content="&lt;?php echo $meta_keywords; ?&gt;"&gt;
  &lt;link rel="shortcut icon" href="../images/favicon.ico" /&gt;
  &lt;link href='http://fonts.googleapis.com/css@family=Open+Sans' rel='stylesheet' type='text/css'&gt;
  &lt;script src="freecontactformvalidation.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      required.add('Full_Name','NOT_EMPTY','Full Name');
      required.add('Email_Address','EMAIL','Email Address');
      required.add('Your_Message','NOT_EMPTY','Your Message');
      required.add('AntiSpam','NOT_EMPTY','Anti-Spam Question');
      &lt;/script&gt;
      &lt;link rel="stylesheet" type="text/css" href="freecontactform.css"&gt;
  &lt;link href="../styles.css" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="../customstyles.css" rel="stylesheet" type="text/css" /&gt;
  &lt;!--ipt type="text/javascript"&gt;
  
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-38670186-3']);
    _gaq.push(['_trackPageview']);
  
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  
  &lt;/scri--&gt;&lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="Top"&gt;
    &lt;div id="InTop"&gt;
      &lt;div id="NaviRight"&gt;
  &lt;div&gt;&lt;a target="_blank" href="&lt;?php echo $fb_url; ?&gt;"&gt;&lt;img src="http://socialesale.com/images/facebook-icon.jpg" alt="Facebook" width="48" height="48" border="0" class="socialicon" /&gt;&lt;/a&gt;&lt;a target="_blank" href="&lt;?php echo $tw_url; ?&gt;"&gt;&lt;img src="http://socialesale.com/images/twitter-icon.png" alt="Twitter" width="48" height="48" border="0" class="socialicon" /&gt;&lt;/a&gt;&lt;a target="_blank" href="&lt;?php echo $gplus_url; ?&gt;"&gt;&lt;img src="http://socialesale.com/images/googleplus-icon.png" alt="GooglePlus" width="48" height="48" border="0" class="socialicon" /&gt;&lt;/a&gt;&lt;a target="_blank" href="&lt;?php echo $youtube_url; ?&gt;"&gt;&lt;img src="http://socialesale.com/images/youtube-icon.png" alt="Youtube" width="48" height="48" border="0" class="socialicon" /&gt;&lt;/a&gt;&lt;a target="_blank" href="&lt;?php echo $pinterest_url; ?&gt;"&gt;&lt;img src="http://socialesale.com/images/pinterest-icon.png" alt="Pinterest" width="48" height="48" border="0" class="socialicon" /&gt;&lt;/a&gt;&lt;a target="_blank" href="&lt;?php echo $instagram_url; ?&gt;"&gt;&lt;img src="http://socialesale.com/images/instagram-icon.png" alt="Instagram" width="48" height="48" border="0" class="socialicon" /&gt;&lt;/a&gt;&lt;/div&gt;
        &lt;div id="Nav"&gt;
          &lt;ul&gt;
            &lt;li&gt;&lt;a href="../contact"&gt;CONTACT&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="../about"&gt;ABOUT&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="../reviews"&gt;REVIEWS&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="../faqs"&gt;FAQ'S&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="../index.php"&gt;HOME&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a href="../index.php"&gt;&lt;img src="../&lt;?php echo $logourl; ?&gt;" alt="Social Website - Social Media Marketing" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="Blue"&gt;
    &lt;div id="InBlue"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href="../index.php"&gt;HOME&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="../facebooklikes"&gt;FACEBOOK&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="../twitterfollowers"&gt;TWITTER&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="../youtubeviews"&gt;YOUTUBE&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="../googleplusones"&gt;GOOGLE&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="../instagramfollowers"&gt;INSTAGRAM&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="../pinterestfollowers"&gt;PINTEREST&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="Shad"&gt;&lt;/div&gt;
  &lt;div id="Main"&gt;
    &lt;div id="Info"&gt;
      &lt;h1&gt;Contact us&lt;/h1&gt;
      &lt;p&gt;If you have any questions about the services we provide, please complete the form below and we will get back to you as soon as possible.&lt;/p&gt;
    &lt;/div&gt;
    &lt;form action="contactprocess.php" method="post" name="freecontactform" id="freecontactform" onsubmit="return validate.check(this)"&gt;
      &lt;table width="550" border="0" cellpadding="0" cellspacing="0"&gt;
        &lt;tr&gt;
          &lt;td valign="top"&gt;Your Name:&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top" class="formtd"&gt;&lt;input name="Full_Name" type="text" class="formtxt" id="Full_Name" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top"&gt;Your Email Address:&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top" class="formtd"&gt;&lt;input name="Email_Address" type="text" class="formtxt" id="Email_Address" maxlength="100" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top"&gt;Your Telephone Number:&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top" class="formtd"&gt;&lt;input name="Telephone_Number" type="text" class="formtxt" id="Telephone_Number" maxlength="100" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top"&gt;Your Message:&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td valign="top" class="formtd"&gt;&lt;textarea name="Your_Message" class="formtxt" id="Your_Message" style="height:160px" maxlength="2000"&gt;&lt;/textarea&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;input name="AntiSpam" type="hidden" id="AntiSpam"  value="25" maxlength="100" /&gt;
            &lt;div class="checkout"&gt;&lt;a href="#" onclick="document.forms['freecontactform'].submit();"&gt;SEND EMAIL&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
      &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;/form&gt;
    &lt;div class="clear"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="Bottom"&gt;&lt;a href="../index.php"&gt;HOME&lt;/a&gt; | &lt;a href="../faqs"&gt;FAQ'S&lt;/a&gt; | &lt;a href="../reviews"&gt;REVIEWS&lt;/a&gt;| &lt;a href="../about"&gt;ABOUT&lt;/a&gt; | &lt;a href="../contact"&gt;CONTACT&lt;/a&gt; | &lt;a href="../purchase-agreement"&gt;PURCHASE AGREEMENT&lt;/a&gt; | &lt;a href="../privacy"&gt;PRIVACY POLICY&lt;/a&gt;&lt;br /&gt;
    &lt;br /&gt;
    Copyright 2014 &amp;copy; &lt;a href="&lt;?php echo $url; ?&gt;"&gt;&lt;?php echo $meta_title;?&gt;.&lt;/a&gt;All rights reserved.&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>contactprocess.php</strong></p>
  
  <pre><code>    &lt;?php
  
  include("../config.php");
  
  if(!$_POST) exit;
  
  $email = $_POST['Email_Address'];
  $error ="";
  $errors ="";
  
  if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $error.="Invalid email address entered!";
      $errors=1;
  }
  
  if($errors==1) echo $error;
  else{
      $values = array ('Full_Name','Email_Address','Your_Message');
      $required = array('Full_Name','Email_Address','Your_Message');
  
  
      $email_subject = "New Message From Your Social Website";
      $email_content = "new message:\n";
  
      foreach($values as $key =&gt; $value){
        if(in_array($value,$required)){
          if ($key != 'subject' &amp;&amp; $key != 'company') {
            if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
          }
          $email_content .= $value.': '.$_POST[$value]."\n";
        }
      }
  
      if(@mail($email,$email_subject,$email_content)) {
          echo 'Message sent!'; 
      } else {
          echo 'ERROR!';
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Also in config.php I have this:</p>
  
  <pre><code>    //contact form email address
  $your_email = "MYEMAIL"; 
  </code></pre>
  
  <p>I have no idea what the problem might be. Someone submits a contact form message, and instead of the message arriving in my email, it arrives in their email. So their message arrives in their email.</p>
  
  <p>Hope someone can help.</p>
  
  <p>Thanks</p>