I have 3 files - no doubt they could be put together...but anyway...
this is the basic contact form with an error report... called contact.php
<?php echo $error ?></span></p>
<form action="contact-confirm.php" method="post" id="contact">
<table width="90%" border="0" cellpadding="3" cellspacing="3" class="tableindent">
<tr>
<td><div align="right">Name:</div></td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td><div align="right">Email:</div></td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td align="right" valign="top">Comments:</td>
<td><textarea name="subject" cols="40" rows="8" id="subject"></textarea></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="-submit" value=" Submit Message " /></td>
</tr>
</table>
</form>
this is the contact-confirm.php
<?
if (empty($_POST['name'])) $error .= "You didn't give us your name.<br>";
if (empty($_POST['email'])) $error .= "You didn't enter your email address.<br>";
if (empty($_POST['subject'])) $error .= "You didn't make any comments or ask a question.<br>";
$str = $text; $text_len = strlen($str);
if($text_len > 800) { $error .= "Sorry, you have used more than permitted 800 characters in your message. Total was $text_len - please shorten your message.<br>"; }
if($email) {
if(isset($_POST['email']))
{
// $email = $email;
// check to make sure email has been filled out with valid address
if (preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i', trim($email))) {
//do nothing the syntax looks good
}
else {$error .= "Your email address has a spelling error<BR>";
}//set error code
// check for valid domain name
$ok = TRUE;
$ok = eregi( "^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email,
$check);
$ok = getmxrr(substr(strstr($check[0], '@'), 1), $dummy);
if($ok === false)
{
$host = substr($email, strpos($email, '@') + 1);
if(gethostbyname($host) != $host)
{
$ok = true;
}
if ($ok != true) {$error .= "That email address does not seem to be valid - please check<br>"; }
// end of check
}
}} // end of email check
if($error) {
include("contact.php");
}
else {
include("contact-success.php");
}
?>
and this is the contact-success.php ...where an e-mail is sent to both parties...
<p>Thanks for filling in the form</p>
<p>
<?php
$email = $_POST['email'];
$title = $_POST['name'];
$subject = $_POST['subject'];
$headers = "From: $email";
$sub = "An www.foobar.com message from $title";
$message .= "
$subject\n\n";
$message2 .= "
Thank you for your email message.
We will respond to it as quickly as we can.
For your reference, the text of your message is added at the end of this email.
Kind regards,
--\n
====================
Your original message was\n
====================\n
$subject\n
";
$headers2 .= "From: noreply@blah.com\n";
$sub2.="Re: A Message from www.blah.com\n";
?>
</p>
<p>Your message has been sent.</p>
<p>We also sent a copy of the message to <nobr><?php print $email; ?>.</nobr></p>
<p>If this is not correct, please
<script type="text/javascript">
document.write('<a href="javascript:history.go(-1);">go back</a>');
</script>
to the contact page and send again. </p>
<?php
$message = stripslashes($message);
$message2 = stripslashes($message2);
$message = strip_tags ($message);
$message2 = strip_tags ($message2);
mail("foobar@foobar.com", $sub, $message, $headers);
mail($email, $sub2, $message2, $headers2);
?>
my question is how do i put in the contact form a question like what colour is the sun, and if any errors come up rather than list the errors - keep any of the fields that are correct the same so they don't have to retype and put in something where there is an error