Reputation: 235
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.
There are 3 files in the contact folder.
freecontactformvalidation.js
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)&&!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<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])&&to_focus.length===0){to_focus=required.field[i][0];}
tmp=false;}}
if(!tmp){alert(error_message);}
if(to_focus.length>0){document.getElementById(to_focus).focus();}
return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length<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>0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};
index.php
<?php include("../config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Contact <?php echo $meta_title; ?></title>
<meta name="description" content="<?php echo $meta_desc; ?>">
<meta name="keywords" content="<?php echo $meta_keywords; ?>">
<link rel="shortcut icon" href="../images/favicon.ico" />
<link href='http://fonts.googleapis.com/css@family=Open+Sans' rel='stylesheet' type='text/css'>
<script src="freecontactformvalidation.js"></script>
<script>
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');
</script>
<link rel="stylesheet" type="text/css" href="freecontactform.css">
<link href="../styles.css" rel="stylesheet" type="text/css" />
<link href="../customstyles.css" rel="stylesheet" type="text/css" />
<!--ipt type="text/javascript">
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);
})();
</scri--></head>
<body>
<div id="Top">
<div id="InTop">
<div id="NaviRight">
<div><a target="_blank" href="<?php echo $fb_url; ?>"><img src="http://socialesale.com/images/facebook-icon.jpg" alt="Facebook" width="48" height="48" border="0" class="socialicon" /></a><a target="_blank" href="<?php echo $tw_url; ?>"><img src="http://socialesale.com/images/twitter-icon.png" alt="Twitter" width="48" height="48" border="0" class="socialicon" /></a><a target="_blank" href="<?php echo $gplus_url; ?>"><img src="http://socialesale.com/images/googleplus-icon.png" alt="GooglePlus" width="48" height="48" border="0" class="socialicon" /></a><a target="_blank" href="<?php echo $youtube_url; ?>"><img src="http://socialesale.com/images/youtube-icon.png" alt="Youtube" width="48" height="48" border="0" class="socialicon" /></a><a target="_blank" href="<?php echo $pinterest_url; ?>"><img src="http://socialesale.com/images/pinterest-icon.png" alt="Pinterest" width="48" height="48" border="0" class="socialicon" /></a><a target="_blank" href="<?php echo $instagram_url; ?>"><img src="http://socialesale.com/images/instagram-icon.png" alt="Instagram" width="48" height="48" border="0" class="socialicon" /></a></div>
<div id="Nav">
<ul>
<li><a href="../contact">CONTACT</a></li>
<li><a href="../about">ABOUT</a></li>
<li><a href="../reviews">REVIEWS</a></li>
<li><a href="../faqs">FAQ'S</a></li>
<li><a href="../index.php">HOME</a></li>
</ul>
</div>
</div>
<a href="../index.php"><img src="../<?php echo $logourl; ?>" alt="Social Website - Social Media Marketing" border="0" /></a></div>
</div>
<div id="Blue">
<div id="InBlue">
<ul>
<li><a href="../index.php">HOME</a></li>
<li><a href="../facebooklikes">FACEBOOK</a></li>
<li><a href="../twitterfollowers">TWITTER</a></li>
<li><a href="../youtubeviews">YOUTUBE</a></li>
<li><a href="../googleplusones">GOOGLE</a></li>
<li><a href="../instagramfollowers">INSTAGRAM</a></li>
<li><a href="../pinterestfollowers">PINTEREST</a></li>
</ul>
</div>
</div>
<div id="Shad"></div>
<div id="Main">
<div id="Info">
<h1>Contact us</h1>
<p>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.</p>
</div>
<form action="contactprocess.php" method="post" name="freecontactform" id="freecontactform" onsubmit="return validate.check(this)">
<table width="550" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">Your Name:</td>
</tr>
<tr>
<td valign="top" class="formtd"><input name="Full_Name" type="text" class="formtxt" id="Full_Name" /></td>
</tr>
<tr>
<td valign="top">Your Email Address:</td>
</tr>
<tr>
<td valign="top" class="formtd"><input name="Email_Address" type="text" class="formtxt" id="Email_Address" maxlength="100" /></td>
</tr>
<tr>
<td valign="top">Your Telephone Number:</td>
</tr>
<tr>
<td valign="top" class="formtd"><input name="Telephone_Number" type="text" class="formtxt" id="Telephone_Number" maxlength="100" /></td>
</tr>
<tr>
<td valign="top">Your Message:</td>
</tr>
<tr>
<td valign="top" class="formtd"><textarea name="Your_Message" class="formtxt" id="Your_Message" style="height:160px" maxlength="2000"></textarea></td>
</tr>
<tr>
<td><input name="AntiSpam" type="hidden" id="AntiSpam" value="25" maxlength="100" />
<div class="checkout"><a href="#" onclick="document.forms['freecontactform'].submit();">SEND EMAIL</a></div></td>
</tr>
</table>
<p> </p>
</form>
<div class="clear"></div>
</div>
<div id="Bottom"><a href="../index.php">HOME</a> | <a href="../faqs">FAQ'S</a> | <a href="../reviews">REVIEWS</a>| <a href="../about">ABOUT</a> | <a href="../contact">CONTACT</a> | <a href="../purchase-agreement">PURCHASE AGREEMENT</a> | <a href="../privacy">PRIVACY POLICY</a><br />
<br />
Copyright 2014 © <a href="<?php echo $url; ?>"><?php echo $meta_title;?>.</a>All rights reserved.</div>
</body>
</html>
contactprocess.php
<?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 => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $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!';
}
}
?>
Also in config.php I have this:
//contact form email address
$your_email = "MYEMAIL";
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.
Hope someone can help.
Thanks
Upvotes: 0
Views: 126
Reputation: 1191
In contactprocess.php you have ;
//Here you store user email.
$email = $_POST['Email_Address'];
(...)
//Then here you send the email to the user
if(@mail($email,$email_subject,$email_content)) {
echo 'Message sent!';
}
What you want is :
if(@mail('[email protected]',$email_subject,$email_content)) {
echo 'Message sent!';
}
Upvotes: 1