Jump to content

POST problems with a contact form


lukeseed

Recommended Posts

Hi,

We just switched to a php site instead of our old ASP/html site.  We are running IIS6 on SBS2003.  I have installed PHP 5.3.2 and the IIS fastCGI.  The site is up and running and for the most part everything is working well.

 

The problem we are having is that our contact page code is not POSTing to the thank_you page, or at least that is what I think the problem is.  When I hit the submit button on the contact form all that comes up is a blank thank_you page with no code, almost as if I had directly tried to access that page from my browser address bar. 

 

I have verified that the mail() function is working with this code

<?php
mail('me@mywebsite.com','Test mail','The mail function is working!');
echo 'Mail sent!';
?>

 

I have verified that the POST function is working with these two pages

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post"> 
<select name="item"> 
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input name="quantity" type="text" /> 
<input type="submit" />
</form>
</body></html>

and

<html><body>
<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];

echo "You ordered ". $quantity . " " . $item . ".<br />";
echo "Thank you for ordering from Tizag Art Supplies!";

?>
</body></html>

 

So that leads me to believe that there is a problem with the coding on our two real pages.  Can anyone lend me another set of eyes on this code and see what the problem is?  The first code is the contact form page with some specific business information left out and the second code is the thank_you page.

<!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 - Company Name</title>
<?php include ("includes/head.php"); ?>


</head>

<body>

<?php include ("includes/header.php"); ?>
<div id="content" style="padding:15px 25px 0px 25px; width:940px; height:840px">
    <div id="left-content">
	<h1>Contact Us</h1>
	<h2>Add us to your team!</h2>

            <h3>Company Name</h3>
            <p>Address<br />
            Address<br />
            Phone Number</p><br />
         
	<div id="contact-form">
        <h3>Use this form to email us</h3>
        <h2>All items required</h2>      
  
<form name="contactform" method="post" action="thank_you.php">
			<div><label>First Name</label><input type="text" size="35" maxlength="256" name="first_name"></div>
			<div><label>Last Name</label><input type="text" size="35" maxlength="256" name="last_name"></div>
			<div><label>E-mail</label><input type="text" size="35" maxlength="256" name="email"></div>
			<div><label>Telephone</label><input type="text" size="35" maxlength="256" name="telephone"></div>
			<div><label>Comments</label>	<textarea name="comments" rows="5" cols="42"></textarea></div><br clear="all" />
			<div><input type="submit" class="button" value="Submit"><input type="reset" class="button" value="Clear Form"></div>
	</form>
	</div>
<br clear="all" />
<h3>Our Location</h3>
      {Google Maps Code}
    
     
      </div>
        
         <div id="sidebar">
         <h3>About Us</h3>
         <p>Company info blah blah<br /><br />

More company info blah blah<br /><br />

More info.</p>
      <br />
        <a class="arrow-link" style="float:right" href="/gallery.php">See Our Work</a>
	</div><!-- #sidebar -->	

      
   </div><!-- end #content -->
   
   
<?php include ("includes/footer.php"); ?>

</body>
</html>

and

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me@mysite.com";
$email_subject = "****** Mail From Our Web Site Contact Page *****";


function died($error) {
	// your error code can go here
	echo "We are very sorry, but there were error(s) found with the form your submitted. ";
	echo "These errors appear below.<br /><br />";
	echo $error."<br /><br />";
	echo "Please go back and fix these errors.<br /><br />";
	die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
	!isset($_POST['last_name']) ||
	!isset($_POST['email']) ||
	!isset($_POST['telephone']) ||
	!isset($_POST['comments'])) {
	died('We are sorry, but there appears to be a problem with the form your submitted.');		
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
  	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
  	$error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
  	$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
  	$error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  $string_exp = "^[0-9 .-]+$";
  if(!eregi($string_exp,$telephone)) {
  	$error_message .= 'The Telephone Number you entered does not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
  	died($error_message);
  }
$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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\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);  

echo'
<!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>Thank You - Company Name</title>
<link rel="stylesheet" href="/includes/site.css" type="text/css" />
<!--[if IE 6]>
<link rel="stylesheet" href="/includes/ie6.css" type="text/css" />
<![endif]-->
<meta name="description" content="Company Info" />
<meta name="keywords" content="lots of keywords " />

</head>

<body>

<div id="header">
<div class="logo"><a href="/"><img src="../images/logo.jpg" alt="Company Logo" border="0" /></a></div>

    <div id="nav">
    	<ul>
        	<li><a href="/" class="home"></a></li>
            <li><a href="/company.php" class="company"></a></li>
            <li><a href="/services/" class="services"></a></li>
            <li><a href="/gallery.php" class="gallery"></a></li>
            <li><a href="/contact.php" class="contact"></a></li>
        </ul>    
</div>

</div>
<div id="wrapper-top"></div>
<div id="wrapper">	<div id="content" style="padding:15px 25px 0px 25px; width:940px;height:500px;">
    <div id="left-content">
	<h1>Thank You</h1>
	<h2>We look forward to working with you.</h2>
        <p>Thank you for contacting our Company. We will be in contact with you shortly.</p><br />
        <a class="arrow-link" href="/">Return to Homepage</a>

</div>
        
         <div id="sidebar">
         <h3>More On Us</h3>
        <p>Company Info</p><br/>

	<p>More info</p>
	<ul>
            <li>Concept development</li>
            <li>Architecture development</li>
            <li>Detailed design</li>
            <li>Testing</li>
            <li>Manufacturing support</li></ul>

	<p>TBlahhah blahhh<br /><br />
	blahh blahh blahh</p><br />

        <a class="arrow-link" style="float:right" href="/gallery.php">View Our Work</a>
	</div><!-- #sidebar -->	
        
        
   </div><!-- end #content -->
</div><!-- end #wrapper -->

<div id="wrapper-bottom"></div>

<div id="footer">
<ul><li><a href="/">Home</a> | </li>
    	<li><a href="/company.php">Company</a> | </li>   
        <li><a href="/services/">Services</a> | </li>

        <li><a href="/gallery.php">Gallery</a> | </li>
        <li><a href="/contact.php">Contact</a> | </li>
        <li><a href="/defaultInternal.htm">Customer Portal</a> | </li>
        <li><a href="/site-map.php">Site Map</a></li>
    </ul>

    <div class="bottom">
    	© 2010 Company  |  All Rights Reserved</div>
</div><!-- end footer -->                 

</body>
</html>
';
?>

<?
}
?>

 

I've been told that this code works on another server but if a simple form and POST works as well as the mail message I am at a loss of why this wouldn't work. Any help would be greatly appreciated.  Thanks,

 

LUke

Link to comment
Share on other sites

Try putting this on your thank_you.php page for debugging purposes

print_r($_POST);

 

This will tell you if the POST values are actually there or not. If that doesn't work then the problem is on your form page. If it does work, then continue debugging your processing page. Insert echo's at crucial steps in the code to validate that variables have the values you expect them to have.

Link to comment
Share on other sites

Try putting this on your thank_you.php page for debugging purposes

print_r($_POST);

 

This will tell you if the POST values are actually there or not. If that doesn't work then the problem is on your form page. If it does work, then continue debugging your processing page. Insert echo's at crucial steps in the code to validate that variables have the values you expect them to have.

 

I inserted this directly after the php opening tag and I am still getting a blank thank_you page.  What does that mean? Where would the hang up be if we are getting to the thank_you page but with no post data? I also fixed the closing php tags and that didn't help either.

 

LUke

Link to comment
Share on other sites

A) Your form and form processing code worked for me after I fixed the php tags near the end of it,

 

B) You are likely still getting a fatal parse error due to bad php syntax (which is the most likely cause of a blank php page),

 

C) You should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, so that all the errors php detects will be reported and displayed.

Link to comment
Share on other sites

A) Your form and form processing code worked for me after I fixed the php tags near the end of it,

 

B) You are likely still getting a fatal parse error due to bad php syntax (which is the most likely cause of a blank php page),

 

C) You should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, so that all the errors php detects will be reported and displayed.

 

You were right!! I thought I changed it but it must have been a backup copy of the thank_you page I changed.  It seems to be working perfectly now.  Thanks so much.

 

I did turn on the error_reporting for a bit and I got this

Warning: mail(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for '-7.0/DST' instead in C:\Inetpub\wwwroot\thank_you.php on line 73 Warning: mail(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for '-7.0/DST' instead in C:\Inetpub\wwwroot\thank_you.php on line 73

Is this something I can safely ignore?

Link to comment
Share on other sites

Because php has the ability to log mail() function calls (see the mail.log setting) it expects the timezone to be set.

 

You could set the timezone to the correct value for your server (in case you decide to use any time dependent functions) to prevent the generation of those Warning messages.

 

Code should not produce any notice, warning, or error messages during its' normal execution. Only for abnormal conditions. If your error log is full of hundreds and thousands of notice and warning messages because you did not correct the condition causing those, it makes it extremely difficult to find REAL problems when they occur, such as when a hacker starts feeding your script all kinds of unexpected data in an attempt to break into your script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.