Hi there,
I have this code I put together from other scripts and stuff I found on the internet,
Somehow it is sending me two emails, one email when I just load the page, the second ofcourse when I submit.
Also, the header() is not sending me to the page I want it to…it just stays on the same form page, if anyone can help me find out what is going on, it would be much appreciated
Thank you,
<style>
.error {color: #FF0000;}
h6
{
font-family: bookman old style;
font-size:20px;
text-align: center;
font-weight: normal;
}
h5
{
font-family: bookman old style;
font-size:15px;
text-align: center;
font-weight: normal;
}
</style>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $websiteErr = $categoryErr = "";
$name = $email = $comment = $website = $category = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["website"])) {
$websiteErr = "URL is required";
} else {
$website = test_input($_POST["website"]);
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
}
}
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
}
if (empty($_POST["category"])) {
$categoryErr = "Category is required";
} else {
$category = test_input($_POST["category"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php include'header.php'?>
<h6>Link Submission</h6>
<h5><p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name Of Site: <input type="text" name="name" value="<?php echo $name;?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
URL: <input type="text" name="website" value="<?php echo $website;?>">
<span class="error">* <?php echo $websiteErr;?></span>
<br><br>
Description: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
<br><br>
Category Of Site: <select size="1" name="category">
<option value="<?php echo $category;?>"> -- Please select -- </option>
<option>Arts</option>
<option>Business</option>
<option>Computers</option>
<option>Games</option>
<option>Health</option>
<option>Home</option>
<option>Kids and Teens</option>
<option>News</option>
<option>Recreation</option>
<option>Reference</option>
<option>Science</option>
<option>Shopping</option>
<option>Society</option>
<option>Sports</option>
<option>World</option>
</select><span class="error">* <?php echo $categoryErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</h5><?php include'footer.php'?>
<?php
$myemail = "[email protected]";
$subject = "Link Submission";
$message = "Your Link Submission form has been submitted by:
Website Name: $name
E-mail: $email
URL: $website
Category: $category
Description:
$comment";
mail($myemail, $subject, $message);
header('Location: submitthanks.php');
?>