PHP contact form help


I have tried to create a direct contact form using PHP, and although the required field warnings etc. are working correctly, when you press submit it doesn’t link to the Thank You page, and the message isn’t delivered. Here is a link to the form:

If anyone can help me it would be much appreciated!

Hello Kayleigh333, add below line in contactform.php at the end. of code.

header(“Location: thanks.html”); #replace thanks.html with your thanks page.
i hope this will helpful for you.
Reply your feedback


Looking at your page you posted, it has a standard form in it.
When posted it goes to “simple-form-1-1/contactform.php”.
So, this page should redirect to the thanks page as Sarthak explained…


make 2 pages

1st page is the form

[code] <?php
ini_set(‘display_errors’, ‘1’);

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Page</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
<div align="center" id="wrapper">
<?php include_once("template_header.php");?>
<div id="content">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<td width="32%" valign="top"><form method="post" action="contact2.php"> Email: <input name="email" type="text"><br> Message:<br>
<textarea name="message" rows="15" cols="40"></textarea><br> <input type="submit"> </form> </td>
<td width="35%" valign="top"></td>
<td width="33%" valign="top"></td>
<?php include_once("template_footer.php");?>

the 2nd page is the php script

<?php $to = ""; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?>

that’s how I did it but if you want it to redirect to thank you page do as sarthak patel did and change the print statment on the php script to

<?php $to = ""; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {header("Location: thanks.html"); } else {header("Location: fail.html"); } ?>

I called the 1st page ‘contact.php’ and the 2nd page ‘contact2’


on you original form you can just add the action to the form

<form action="contact2.php">

and just add the php code i put up and it will send and redirect, it works for me