Hi,
I’m new to web design and php, so, sorry if there is something easy I’ve overlooked here. I’m trying to design a simple email contact form - the contact form itself actually DOES work. When I submit the form I do receive emails (with the code below with correct address), but the problem is the page then does not redirect to a ‘contact submitted’ page on my website. Nothing happens and it stays on the same contact form page (although it looks like it is trying to connect for a second). I have spent a long time looking online and trying different things, but nothing works and I am wondering whether it is something to do with limitations of a free 000webhost account (do I have to edit htaccess?). I have tried both header() and echo<> (see code) and I don’t think I have echoed anything before the header(). I know that I still have to fix the POST for sql injection. I have other forms on my website that post data to my sql database and then redirect without any problems. I don’t really want to upgrade my account yet as this website is a test run. I’d appreciate any advice.Thanks!
<head>
<title>Contact us</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body >
<form action="formSubmit.php" method="post">
<div>
<label class="description" for="first_name">First name</label>
<p><input id="first_name" type="text" name= "first_name" class="element text large" maxlength="255" value="" required /></p>
</div>
<div>
<label class="description" for="last_name">Last name</label>
<p><input id="last_name" type="text" name= "last_name" class="element text large" maxlength="255" value="" required /></p>
</div>
<div>
<label class="description" for="email">email</label>
<p><input id="email" type="text" name= "email" class="element text large" maxlength="255" value="" required /></p>
</div>
<div>
<label class="description" for="comments">comments</label>
<p><input id="comments" type="text" name= "comments" class="element text large" maxlength="255" value="" required /></p>
</div>
<div>
<br>
<li class="buttons">
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
<input id="reset" class="button_text" type="reset" value="Start Over">
</div>
</li> </form>
</body>
ob_start();
error_reporting(E_ALL);
/* Set e-mail recipient */
$myemail = "myemail@address.com";
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$subject= $_POST['comments']; // required
/* prepare the message for the e-mail */
$message = "
Name: $first_name
E-mail: $email_from
Subject: $comments
Message:
$comments
";
/* Send the message using mail() function */
$headers = 'From: '.$email_from."
";
mail($myemail, $subject, $message,$headers);
/* Redirect visitor to the thank you page */
header('Location: http://.../contact-submitted.html');
//echo "<meta http-equiv='Refresh' content='0; URL=http://.../contact-submitted.html'>";
ob_end_flush();
exit();