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:

http://www.cpdautomotive.com/askus.html

If anyone can help me it would be much appreciated!

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

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

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
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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" />
</head>
<body>
<div align="center" id="wrapper">
<?php include_once("template_header.php");?>
<div id="content">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<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>
</tr>
</table>
 
</div>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>[/code]

the 2nd page is the php script

<?php $to = "[email protected]"; $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 = "[email protected]"; $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

Sponsor our Newsletter | Privacy Policy | Terms of Service