My questions are as follows:
++++ This line is flagged as an error. Why?? (it’s exactly the same as line 8 rows above, which is NOT flagged)
Error message is:
PHP Parse error: syntax error, unexpected '}' in /mailit.php on line 44
PHP Parse error: syntax error, unexpected '}' in /mailit.php on line 44
+++++ How can I make this pattern validate a specific number that was input?
++++++ I want this line to validate_form_email, how do I do it?
+++++++ I want this to take user to thanks.html page that will also echo info sent.
Also, I would like to trim input of special chars., where can I do this in the function?
Thanks in Advance to anyone that took the time to try and help. I tried to figure it out for one entire week, so please understand that I want to learn it, not just ask someone else to do it for me. But for the life of me I can't get this. Where did I go wrong? (BTW: I successfully tested server with simple email test).
<?php
if (isset($_POST['submitted'])) {
//to load var
$_POST = "name";
$_POST = "email";
$_POST = "about";
$_POST = "nospam";
$_POST = "textarea";
$errors = array();
$name = $_POST['name'];
$email = $_POST['email'];
$about = $_POST['about'];
$nospam = $_POST['nospam'];
$textarea = $_POST['textarea'];
//validation
if (!empty($_POST['name'])) {
$name = $_POST['name'];
} else { $errors[] = 'Please enter your Name.';}
if (preg_match($pattern,$name)){ $name = $_POST['name'];}
$pattern = "/^[a-zA-Z0-9_]{2,20}/";
} else {$errors[] = 'Your Name can only contain letters and numbers.';}
if (!empty($_POST['email'])) {
$email = $_POST['email'];
} else {$errors[] = 'Please enter your email address.';}
if (preg_match($pattern,$email)){ $email = $_POST['email'];}
$pattern = "/^[a-zA-Z0-9_]{2,20}/";
} else {$errors[] = 'Your Email must be Valid.';}
if (!empty($_POST['about'])) {
$about = $_POST['about'];
} else {$errors[] = 'Please enter a Subject here.';}
if (preg_match($pattern,$about)){ $about = $_POST['about'];}
$pattern = "/^[a-zA-Z0-9_]{2,20}/";
} else {$errors[] = 'What is this contact about?';}
if (!empty($_POST['nospam'])) {
$nospam = $_POST['nospam'];
} else {$errors[] = 'Please answer the Anti-Spam Question';}
$pattern = ('/^[a-zA-Z0-9_]{2,20}/');
if (preg_match($pattern,$nospam)){ $nospam = $_POST['nospam'];}
} else {$errors[] = 'Hmmm. Can you try this again?';}
if (!empty($_POST['textarea'])) {
$textarea = $_POST['textarea'];
} else {$errors[] = 'Please enter your Message.';}
if (preg_match($pattern,$textarea)){ $textarea = $_POST['textarea'];}
$pattern = "/^[a-zA-Z0-9_]{2,20}/";
} else {$errors[] = 'Your Message can only contain regular letters and numbers.';}
//compile and send email
if (isset($_POST['submitted'])) {
if (empty($errors)) {
$to = "info@ anything.com";
$from = "info@anything.com";
$subject = "Comment from anything Website";
$message = "Message from" . $_POST['name'] . "rnrn";
"Email Address " . $_POST['email'] . "rnrn";
"About " . $_POST['about'] . "rnrn";
"Text " . $_POST['textarea'] . "";
}
}
mail($to, $from, $subject, $message);
//verify submission and show errors
if (isset($_POST['submitted'])) {
if (!empty($errors)) {
echo '<hr /><h3>The following occurred:</h3><ul>';
foreach ($errors as $msg) { echo '<li>'. $msg . '</li>';}
echo '</ul><h3>Your mail could not be sent due to input errors.</h3><hr />';}
else {
echo '<hr /><h3 align="center">Your mail was sent. Thank you!</h3><hr /><p>Below is the message that you sent.</p>';
echo "Message from" . $name . " " . $email . " " . $subject. " " . $textarea . "";
}
}
exit:('Redirecting you to http://www.anything.com/swg/thankyou.html');