hellllloooo again

does anyone know how i can tweak my files so that when someone has completed an email form, it stays on the same page and says Thank you - your message has been received etc?

at the moment i have my form in my contact us html file, and then it transfers to another file called send_form_email.php which is just a plain white background with black font on.

Is there any way of getting that to come up in an iframe or something similar so my logo etc and links are still visible?

thanks very much in advance;)

Recommended Answers

All 3 Replies

Just add the following line at the end of your php code:

header("Location: index.html");

This will redirect the page.

Alternatively you can contain the whole page and the email script in the same file, so that a redirect is not needed, but this might require you to rewrite the code in your site, so is possibly not a good idea on this occasion.

hi thank a lot for that

this is my php code, where would i insert this please?

      if(isset($_POST['email'])) {
	$email_to = "email@domain.co.uk";
	$email_subject = "Web Enquiry";
	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['name']) || !isset($_POST['email']) || 
      !isset($_POST['message'])) { died('We are sorry, but there appears to be a 
      problem with the form your submitted.'); } $name = $_POST['name']; // 
      required $email_from = $_POST['email']; // required $message = 
      $_POST['message']; // required $error_message = ""; $email_exp = 
      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,$name)) { $error_message .= 'The Name you 
      entered does not appear to be valid.<BR>'; } if(strlen($message) &lt; 2) { 
      $error_message .= 'The Message you entered do not appear to be 
      valid.<BR>'; } if(strlen($error_message) &gt; 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 .= "Name: 
      ".clean_string($name)."\n"; $email_message .= "Email: 
      ".clean_string($email_from)."\n"; $email_message .= "Message: 
      ".clean_string($message)."\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); 
      ?&gt; <!-- include your own success html here -->Thank you for contacting 
      us. Your message has been received.We will be in touch 
      with you very soon. <?

thanks a lot!!

i got the code from an online tutorial, but id prefer it just to say, sorry there was an error if the email address isnt filled out and if it is, then thanks we have your message etc, its seems very logn winded, but im out of my depth so didnt really want to fiddle with it

thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.