PHP Contact Forms Not Cooperating

Hello all and thanks for taking the time to read this. I have a frustrating problem with one of the contact forms on a website I am working on. The contact form on the contact.html page does what it is supposed to and collapses after you hit the SEND button and reads “Message Sent!” in place of it (in the same

box). However, the contact form on the index.html file does not collapse after you hit SEND, rather it redirects people to a blank white page that says “Message Sent!”. I am using the same contact.php file for both and the exact same HTML form code for both. The only difference is they sit in two different
boxes because of the width of my work space on the pages. The CSS for the two
boxes are identical except for the width. Please help me solve this!

Here is the contact.php file:

[php]<?php

if(!$_POST) exit;

$email = $_POST[‘email’];

//$error[] = preg_match(’/\b[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}\b/i’, $POST[‘email’]) ? ‘’ : ‘INVALID EMAIL ADDRESS’;
if(!preg_match("/^[a-z0-9]+([
\.-][a-z0-9]+)" ."@"."([a-z0-9]+([.-][a-z0-9]+))+"."\.[a-z]{2,}"."$/i",$email )){
$error.=“Invalid email address entered”;
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array (‘name’,‘email’,‘message’);
$required = array(‘name’,‘email’,‘message’);

$your_email = "[email protected]";
$email_subject = "From EricaWaterman.com, Phone: ".$_POST['subject'];
$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($your_email,$email_subject,$email_content)) {
	echo 'Message sent!'; 
} else {
	echo 'ERROR!';
}

}
?>[/php]

Here is the html for the form found on the index.html page and the contact.html page:

<form action="contact.php" method="post" id="contactform"> <ol> <li> <label for="name">First 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="subject">Phone</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 type="image" name="imageField" id="imageField" src="images/send.gif" class="send" /><br /> *Required Fields <div class="clr"></div> </li> </ol> </form>

what you currently have is form which on submit it sends the data to another page(contact.php)
which is the blank page you are talking about

in order for you to be able to tell people the results of the message sent or not you need to run ur php logic on the same page.

what i mean by this you must change your index.html to index.php and have html and logic there.

you can do it other ways but this way is far way easier

i merged both yuor html and php code to do what you want
[php]

<?php IF (isset($_POST['imageField'])) { $email = $_POST['email']; // $error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$/i",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "[email protected]"; $email_subject = "From EricaWaterman.com, Phone: ".$_POST['subject']; $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($your_email,$email_subject,$email_content)) { $msg= "Message sent!"; } else { $msg= "Message not sent!"; } } } ?>
  1. First Name *
  2. Your email *
  3. Phone
  4. Message *

  5. *Required Fields
    <?php if (!empty($msg)) { echo $msg; } ?>
[/php]

however i changed the button type image to submit

Sponsor our Newsletter | Privacy Policy | Terms of Service