Yes we are. Now that the php is actually being parsed, you can start on the code
The code I’m posting hasn’t been tested, the checks on the form field values are very elementary, and I changed the logic so the form sends its values to itself (and not to a separate script) because that way it’s easier to handle errors (IMO). It means that your form page must be called “contact_page.php” instead of “contact_page.html”. After the mail has been sent, it redirects to your confirmation page.
In the code I left out all html that comes before and after the form to keep things simple. You’ll have to add that where I indicated (see script). I hope all is clear
<?php
// initialize error messages array
$errors = array();
// if the form has been submitted, check the form field values
// if all is ok, send the mail and redirect
// if something is wrong, display the form with error messages
if (isset($_POST['required'])) {
// check email
if (!isset($_POST['required']) || trim($_POST['required']) == '') {
$errors['email'] = 'Email required';
}
// check name
if (!isset($_POST['realname']) || trim($_POST['realname']) == '') {
$errors['realname'] = 'Name required';
}
// check message
if (!isset($_POST['message']) || trim($_POST['message']) == '') {
$errors['message'] = 'Message required';
}
// if no errors, send mail and redirect
if (count($errors) == 0) {
// Subject of email sent to you.
$subject = 'Results from Contact form';
// Your email address. This is where the form information will be sent.
$emailadd = 'xxxxxxx@xxxxxx.com';
// the text to be emailed
$text = "
email: " . $_POST['email'] . "\
\
name: " . $_POST['realname'] . "\
\
message: " . $_POST['message'] . "\
\
";
mail($emailadd, $subject, $text);
header('Location: http://www.ijacobs.com/confirmation.html');
exit();
}
}
// Below this part you'll have to add all the html code of your
// form page. For simplicities sake, I'll only show the form code:
?>
...
... add all html here that goes before the form section
...
<section id="form">
<?php
// show errors, if any
foreach ($errors as $key => $value) {
echo "<p>$value</p>";
}
?>
<form action="" method="post">
<input type="hidden" name="required" value="yes"/>
E-mail: <input type="email" size="30" name="email"/>
<br />
Name: <input type="text" size="30" name="realname"/>
<br />
Message:<br />
<textarea cols="30" rows="10" name="message"></textarea>
<br />
<input type="submit" value="submit"/>
</form>
</section>
...
... at all html here that goes after the form section
...