what you said made sense. I can see now where the problem is that you pointed out. I made the changes that you said would help with splitting it up into two parts but something is wrong in the syntax and it is giving me a parsing error on line 79 which is just the closing php tag "?>"
Here is what the code looks like:
<?php
error_reporting(E_ALL ^ E_NOTICE);
$your_email = "myemail@fakedomain.com";
$subject = "Message via your contact form";
$empty_fields_message = "<p>Please go back and complete all the fields that are required in the form.</p>";
$thankyou_message = "<p>Thankyou. Your message has been sent.</p>";
$invalid_content = "<p>You have entered invalid content into the mail form. For security issues we do not allow special characters.</p>";
$name = stripslashes($_POST['txtname']);
$email = stripslashes($_POST['txtemail']);
$message = stripslashes($_POST['txtmessage']);
if (!isset($_POST['txtname'])) {
?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p><label for="txtname">Name:</label><br />
<input type="text" title="Enter your name" name="txtname" /></p>
<p><label for="txtemail">Email:</label><br />
<input type="text" title="Enter your email address" name="txtemail" /></p>
<p><label for="txtmessage">Your message:</label><br />
<textarea title="Enter your message" name="txtmessage"></textarea></p>
<p><label title="Send your message">
<input type="submit" value="send" /></label></p>
</form>
<?php
} else {
//checks to see a field has \n or \r in the data and if it does it does not send the email
if (eregi("\r",$email) || eregi("\n",$email)) {
echo $invalid_content;
die ();
}
elseif (empty($name) || empty($email) || empty($message)) {
echo $empty_fields_message;
}
else {
// Check the refering URL
$referer = $_SERVER['HTTP_REFERER'];
// Get the URL of this page
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
// If the referring URL and the URL of this page don't match then
// display a message and don't send the email.
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL.";
exit;
}
// The URLs matched so send the email
mail($your_email, $subject, $message, "From: $name <$email>");
// Display the thankyou message
echo $thankyou_message;
}
?>
I have been looking through it and can not find anything wrong. All curly brackets have closing tags it seems and can't see any place that I missed a semi-colon.
Do I have to remove the php openning and closing tags in the middle of the page to make it one large script? I wouldn't think I would but not sure.
Thanks again for the help with this.