Thanks for being patient with me, I'll admit that this is a friends code, and I've been assigned to fix it, so I may have overlooked something obvious.
I replay the if($success) bit that you suggested for debugging. Upon submission, I did receive the "...success..." text on the page, but it did not change to contactthanks.php like I have hoped.
So, below is my code at this point:
First, contact.html, the page on which the form is located:
Code: Select all
<!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><title>XXXXXXXX</title>
<link rel="shortcut icon" href="favicon.gif" />
<link rel="icon" href="/favicon.gif" type="image/gif" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="XXXXXXXXXXXXXXXXXX" />
<meta name="keywords" content="XXXXXXXXXXXXXXXXXXXXX" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function(){
$('#contactform').submit(function(){ var action = $(this).attr('action');
$.post(action, { name: $('#name').val(),
email: $('#email').val(),
company: $('#company').val(),
subject: $('#subject').val(),
message: $('#message').val()
},
function(data){
$('#contactform #submit').attr('disabled','');
$('.response').remove();
$('#contactform').before('<p class="response">'+data+'</p>');
$('.response').slideDown();
if(data=='Message sent!') $('#contactform').slideUp();
}
); return false;
});
});
// ]]>
</script>
</head>
<body>
<div class="main">
<div class="header">
<div class="logo"><a href="index.html"><img src="images/logo.gif" alt="logo" border="0" height="140" width="334" /></a></div>
<div style="width: 550px; text-align: right;" class="simple_text">
Search </div>
<div style="margin-left: 0px; width: 276px;" class="search">
<form style="margin-left: 0px; width: 261px;" name="search" method="post" action="search1.php"> <input name="find" type="text" />
<select name="field"><option value="xxxx">XXXX</option><option value="xxxxx">xxxxx</option><option value="XXXX">xxxx</option></select>
<input name="searching" value="yes" type="hidden" /><input id="sort" name="sort" value="price" type="hidden" /><input id="direction" name="direction" value="DESC" type="hidden" /><input name="search" src="images/search.gif" class="button" type="image" /></form>
</div>
<div class="clr"></div>
<div class="header_text_bg2">
<div class="header_text2">
<h2><span>Contact </span> Us </h2>
<p>XXXXXXXXXXXXXX</p>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
<div class="clr"></div>
<div class="menu_resize">
<div class="menu">
<div style="width: 512px;" class="menu">
<ul>
<li><a href="index.html"><span>Home</span></a></li>
<li><a href="portfolio.html"><span>About Us</span></a></li>
<li><a href="login.php"><span>Login</span></a></li>
<li><a href="register.php"><span>Register</span></a></li>
<li><a href="member.php"><span>Account</span></a></li>
<li><a href="contact.html" class="active"><span>Contact
us</span></a></li>
</ul>
</div>
</div>
<div class="Twitter"><img src="images/twitter.gif" alt="picture" height="20" width="20" />
<p> <a target="_blank" href="http://www.twitter.com/xxxxxxxxxxx">Follow us on Twitter</a></p>
</div>
<div class="clr"></div>
</div>
</div>
<div class="clr"></div>
<div class="body">
<div class="body_big">
<h2><span>Contact </span> Form</h2>
<p><strong>Tell Us What's On Your Mind</strong></p>
<div class="bg"></div>
<form action="contact.php" method="post" id="contactform">
<ol>
<li> <label for="name">Name <span class="red">*</span></label> <input id="name" name="name" class="text" /> </li>
<li> <label for="email">Your Email <span class="red">*</span></label> <input id="email" name="email" class="text" /> </li>
<li> <label for="company">Company</label>
<input id="company" name="company" class="text" /></li>
<li> <label for="subject">Subject <span class="red">*</span></label>
<input id="subject" name="subject" class="text" /></li>
<li> <label for="message">Message <span class="red">*</span></label> <textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons"> <input name="imageField" id="imageField" src="images/send.gif" type="image" />
</li>
</ol>
</form>
</div>
<div class="body_small">
<h2><span>Get </span> in touch!</h2>
<p><strong>Tel:</strong> +XXX XXX XXXX<strong></strong><br />
<strong>Email:</strong> <a href="contact.html#">support@xxxxxxxxxx.com</a><br />
<strong>Address:</strong> XXXXXXXXXXX</p>
<p><a href="cart.php">View Cart</a> </p>
</div>
<div class="clr"></div>
</div>
<div class="footer">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="portfolio.html">Company Information</a></li>
<li><a href="member.php">User Page</a></li>
<li><a href="terms.php">Terms & Conditions</a></li>
<li><a href="privacy.php">Privacy Policy</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="http://www.twitter.com/xxxxxxxxx"><img src="images/twitter_footer.gif" alt="picture" border="0" height="15" width="80" /></a></li>
</ul>
<p>Copyright © 2010 XXXXXXXXXXXXX.
All Rights Reserved</p>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
</body></html>
Next, the relevant PHP file, contact.php
Code: Select all
<?php
function isValidEmail($address) {
return preg_match("/^[a-z0-9._\-]+[@]([a-z0-9\-]+[.])+([a-z]{2,4})\$/i",
$address);
}
$EmailFrom = "Contact Form";
$EmailTo = "support@xxxxxxxxx.com";
$Subject = Trim(stripslashes($_POST['subject']));
$Name =Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));
if(empty($Name)||empty($Email)||empty($Message)) {
header('Location: http://www.xxxxxxxxx.com/error.htm');
exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
if(!isValidEmail($Email)) {
header('Location: http://www.xxxxxxxxxx.com/error.htm');
exit;
}
else {
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
}
if ($success){
echo "... Success...";
//header('Location: http://www.xxxxxxxxxx.com/contactthanks.php');
exit;
}
else{
echo "... Fail!! .." . $success . " this was the value of success variable";
//header('Location: http://www.xxxxxxxxx.com/error.htm');
exit;
}
?>
Lastly, error.htm:
Code: Select all
<!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><title>XXXXXXXX</title>
<link rel="shortcut icon" href="favicon.gif" />
<link rel="icon" href="/favicon.gif" type="image/gif" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="xxxxxxxxxxxx" />
<meta name="keywords" content="xxxxxxxxxxxxxxx" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="main">
<div class="header">
<div class="logo"><a href="index.html"><img src="images/logo.gif" alt="logo" border="0" height="140" width="334" /></a></div>
<div style="width: 550px; text-align: right;" class="simple_text">
Search </div>
<div style="margin-left: 0px; width: 276px;" class="search">
<form style="margin-left: 0px; width: 261px;" name="search" method="post" action="search1.php"> <input name="find" type="text" />
<select name="field"><option value="xxxxxx">xxxxxxx</option><option value="xxxxxxx">xxxxxx</option><option value="xxxx">xxxx</option></select>
<input name="searching" value="yes" type="hidden" /><input id="sort" name="sort" value="price" type="hidden" /><input id="direction" name="direction" value="DESC" type="hidden" /><input name="search" src="images/search.gif" class="button" type="image" /></form>
</div>
<div class="clr"></div>
<div class="header_text_bg2">
<div class="header_text2">
<h2><span>Contact </span> Us </h2>
<p>xxxxxxxxxxxxxxxx</p>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
<div class="clr"></div>
<div class="menu_resize">
<div class="menu">
<div style="width: 512px;" class="menu">
<ul>
<li><a href="index.html"><span>Home</span></a></li>
<li><a href="portfolio.html"><span>About Us</span></a></li>
<li><a href="login.php"><span>Login</span></a></li>
<li><a href="register.php"><span>Register</span></a></li>
<li><a href="member.php"><span>Account</span></a></li>
<li><a href="contact.html" class="active"><span>Contact
us</span></a></li>
</ul>
</div>
</div>
<div class="Twitter"><img src="images/twitter.gif" alt="picture" height="20" width="20" />
<p> <a target="_blank" href="http://www.twitter.com/xxxxxxxxx">Follow us on Twitter</a></p>
</div>
<div class="clr"></div>
</div>
</div>
<div class="clr"></div>
<div class="body">
<div class="body_big">
<h2><span>We're </span> Sorry</h2>
<p><strong>An Error Has Occurred. Please Try Again.</strong></p>
</div>
<div class="bg"></div>
<p><a href="http://www.xxxxxxxxxx.com/contact.html">Back to Contact Form</a></p>
</div>
<div class="body_small">
<h2><span>Get </span> in touch!</h2>
<p><strong>Tel:</strong> +xxx xxx xxxx<strong></strong><br />
<strong>Email:</strong> <a href="contact.html#">support@xxxxxxxxx.com</a><br />
<strong>Address:</strong> xxxxxxxxxxx</p>
<p><a href="cart.php">View Cart</a> </p>
</div>
<div class="clr"></div>
</div>
<div class="footer">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="portfolio.html">Company Information</a></li>
<li><a href="member.php">User Page</a></li>
<li><a href="terms.php">Terms & Conditions</a></li>
<li><a href="privacy.php">Privacy Policy</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="http://www.twitter.com/xxxxxxxxxx"><img src="images/twitter_footer.gif" alt="picture" border="0" height="15" width="80" /></a></li>
</ul>
<p>Copyright © 2010 xxxxxxxxxxx
All Rights Reserved</p>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
</body></html>