Jump to content

Newbie needs help please


cmf

Recommended Posts

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 :)

 

 

Link to comment
Share on other sites

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!';
}
}
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.