Help needed with PHP Contact Form
Hello,
I'm using PHP to send some information from a form. It's working fine in terms of the emails but there are two things that I can't seem to do.
- Ensure that the email address uses a valid format.
- Stop the inputted data from being cleared in the case that the form has been filled out incorrectly.
The form from contact.php
HTML Code:
<form action="formSender.php" method="post">
<h3>Contact Form</h3>
<label for="name" id="firstLabel">Name:</label>
<input type="text" name="name"><br>
<label for="email">Email:</label>
<input type="text" name="email"><br>
<input type="submit" value="Send" />
</form>
<?php
$send = $_REQUEST['send'];
if ($send == "yes")
{echo 'Your details have been sent. Thankyou! '; }
if ($send == "no")
{echo 'Something went wrong. Please try again.'; }
?>
formSender.php
PHP Code:
<?php
// prepare the redirect
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
//get details for the emails from the form
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
//check to see if the form has been filled out
if($name != "" & $email != "") {
//send the emails
//[....]
//redirect to the original page and show a success note.
$extra = "contact.php?send=yes";
}
//if the form hasn't been filled out
else {
//redirect to orginal page and show an error message.
$extra = "contact.php?send=no";
}
header("Location: http://$host$uri/$extra");
exit;
?>
Can anybody help?
Thanks,
dog