Jump to content

Making A Contact Form Success Message In Php


Recommended Posts

I would like to show a message after someone sends me a email. Stating whether there email was sent or not. Right now they are sent to a new page.I don't want the page to reload. And if possible I want to pick where the text would show up.This is the PHP I'm using now.

<?php  		$emailsubject = 'Contact';		$webMaster = 'youwillnotsendmespam@blah.blah';  		$nameField = $_POST ['name'];		$emailField = $_POST ['email'];		$messageField = $_POST ['message'];  		$body = <<<EOD	<hr>	Name: $nameField <br>	Email: $emailField <br>	Message: $messageField <br>	<hr>	EOD;  		$headers = "From: $emailField\r\n";		$headers .= "Content-type: text/html\r\n";		$success = mail($webMaster, $emailsubject, $body, $headers);  		$theResults = <<<EOD	<html>	  <head>	  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">	  </head>	  <div>	  <div align="left">Thank you for contacting me!</div>	  </div>	  </body>	  </html> EOD;  echo "$theResults"  ?>

Would this code work without a reload? Or do I have to use AJAX?

<?php  		$emailsubject = 'Contact';		$webMaster = 'youwillnotsendmespam@blah.blah';  		$nameField = $_POST ['name'];		$emailField = $_POST ['email'];		$messageField = $_POST ['message'];</font>  	 $body = <<<EOD	<hr>	Name: $nameField <br>	Email: $emailField <br>	Message: $messageField <br>	<hr>	EOD;  		$headers = "From: $emailField\r\n";		$headers .= "Content-type: text/html\r\n";		$success = mail($webMaster, $emailsubject, $body, $headers);  	 if ($success)			echo "Your message has been sent. I will get back to you as soon as possible.";		   else			echo "There has been a error! Make sure you have a working internet connection and try again.";

Any help would be very helpful.Thanks

Edited by SuperPaperSam
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...