Creating a Contact Form Thank You Page and Redirect Using PHP




Send Your Users to a Custom Thank You Page Once Their Form Has Been Submitted

Because your form action is calling a separate page for processing rather then using itself (we will cover that later), you need to somehow let your visitor know that information has been sent.

To do this, you can pretty much use any html page with text as you normally would, and just place the php code at the top of the page.  So for example,  if you want to say something like "Thank You, Your information Has Been Submitted".  You would put your php at the top like this ...

<?PHP
$email = $_POST["emailaddress"];

$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";

$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";

$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";

$usermessage = "Thank you for subscribing to our mailing list.";

mail($to,$subject,$message,$headers);

mail($user,$usersubject,$usermessage,$userheaders);

?>

Click Here to have me build your custom contact form for you

Then the html below would look like this ...

<html>
<body>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div align="center">Thank You, Your Information Has Been Submitted</div>
</td>
</tr>
</table>
</body>
</html>

So here is the full code for the "process.php" page to show the thank you message when they submit their form.  Keep in mind that the page still has to have a .php extension for your form to process correctly.  It will still read the html just fine.

<?PHP
$email = $_POST["emailaddress"];

$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";

$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";

$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";

$usermessage = "Thank you for subscribing to our mailing list.";

mail($to,$subject,$message,$headers);

mail($user,$usersubject,$usermessage,$userheaders);

?>

<html>
<body>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div align="center">Thank You, Your Information Has Been Submitted</div>
</td>
</tr>
</table>
</body>
</html>

Or, if you prefer to redirect them to a new page and keep the process.php script completely separate and simply send them to a thank you page after the process has taken place, just put this redirect command after the mail function within your php script.

header("Location: thankyou.html");

 

Previous   |  Next

Special Package Offer

    Discounted deal on all of our php contact form scripts as a bundle package