email php help

Hi,

I’ve ran my php code through a validator and fixed up the problems, but when I press the submit button on my website it still throws errors. I don’t have a clue what to fix.

– indicates error line

<?php $recipient = 'myemail.com'; $email = $_POST['email']; $subject = $_POST['subject']; $yourname = $post['yourname']; //required $deliveryaddress = $_post['deliveryaddress']; //required $youremail = $_post['youremail']; $contactnumber = $_post['contactnumber']; //required $deliverydate = $_post['deliverydate']; //required $comment = $_post['comment']; if (!preg_match("/^[\w\+\-.~]+\@[\-\w\.\!]+$/", $youremail)) $messages[] = "This is not a valid email address."; if (!preg_match("/^[\w\ \+\-\'\"\]+$/", $yourname)) -- $messages[] = "This required field was left blank."; if (!preg_match("/^[\w\+\-\'\"\ \,\]+$/", $deliveryaddress)) -- $messages[] = "This required field was left blank."; if (!preg_match("/^[\w\(\)\,\]+$/", $contactnumber)) -- $messages[] = "This required field was left blank."; if (!preg_match("/^[\w\]+$/", $deliverydate)) -- $messages[] = "This required field was left blank."; if (!preg_match("/^[\w\+\-\'\"\ \.\,\(\)\?\!\]+$/", $comment)) { -- }else { #Send email mail("myemail.com", "New order", $body, "From: $yourname <$youremail>\r\n" . "Reply-To: $yourname <$youremail>\r\n"); echo("

Your order has been sent. Thank you!

\n"); } ?>

These are the errors:

Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 17 in /home3/vegiepat/public_html/vegiepatchbh/email.php on line 16

Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 19 in /home3/vegiepat/public_html/vegiepatchbh/email.php on line 19

Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 14 in /home3/vegiepat/public_html/vegiepatchbh/email.php on line 22

Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 8 in /home3/vegiepat/public_html/vegiepatchbh/email.php on line 25

Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 29 in /home3/vegiepat/public_html/vegiepatchbh/email.php on line 28

Your help is really appreciated.

You email validation code seems a bit off. try the one on

http://www.w3schools.com/php/php_form_url_email.asp

if that helps it means your validation codes are wrong and you should replace them.

If you still get the errors it means there is something wrong with the variable you send to !preg_match function, meaning all the $_POST’s. In that case, echo all of them and post here.

easy way to do this is to just dump the entire array

[php]echo ‘

’; // this gives us a preformatted text, makes array/objects pretty-print
var_dump($_POST);[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service