cmf Posted June 2, 2013 Share Posted June 2, 2013 I get this message when hit submit button on my form. Warning: preg_match() [function.preg-match]: No ending delimiter '^' found It is on a contact form. The email gets sent and I receive, however, I have no idean how to get rid of this message. Thanks for your help Quote Link to comment Share on other sites More sharing options...
boompa Posted June 2, 2013 Share Posted June 2, 2013 You will have to provide the code that's generating this error. Quote Link to comment Share on other sites More sharing options...
cmf Posted June 2, 2013 Author Share Posted June 2, 2013 I hope this is what you need: <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(preg_match("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "cmf.lhp@gmail.com"; $email_subject = "Web Inquiry: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> Quote Link to comment Share on other sites More sharing options...
cpd Posted June 2, 2013 Share Posted June 2, 2013 Your if(preg_match... has no ending delimiter and from the look of it no starting one either. I assume you've used ^ to signify the beginning of the string. Insert delimiters, e.g. preg_match("#([A-Z0-9]+)#", $string) where the # is the delimiter. Quote Link to comment Share on other sites More sharing options...
cmf Posted June 2, 2013 Author Share Posted June 2, 2013 Thanks cpd; this is my first form using php I have no idea what you mean; correction, I have no idea what i'm doing I've been reading all day about this issue and am not expecting you to solve my problem (unless you really want to help a grandma LOL)). Do you mind telling me what I have to change in the above code I posted? PS you are really cute! Quote Link to comment Share on other sites More sharing options...
cpd Posted June 2, 2013 Share Posted June 2, 2013 Change if(preg_match("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ to if(preg_match("#^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$#",$email )){ And thanks. Quote Link to comment Share on other sites More sharing options...
cmf Posted June 3, 2013 Author Share Posted June 3, 2013 Reporting back that it worked! Thank you for saving me hours of research! Is it true that I should move the php file out of root directory for security purposes? Quote Link to comment Share on other sites More sharing options...
cpd Posted June 3, 2013 Share Posted June 3, 2013 Not necessarily. Its dependent on the functionality of your PHP script. Many people move scripts outside the public domain for added security but if its a simple template script you don't necessarily have to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.