Page 1 of 1

Compilation failed: range out of order ...-Beginner question

Posted: Mon Nov 02, 2009 2:21 am
by Xrcr9709
Hello, I'm a complete beginner in php:

Here's the error I got :
Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 12 in /home/tc81/public_html/mktgsi/contact/index.php on line 60
false

And here my current code :

Code: Select all

<?php
function is_valid_email($mail)
    {
      if(preg_match("/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $mail) > 0)
        {
            return true;
        }
      else
        {
            return false;
        }
    }
 
$to = "---@---.---";
$subject = $_REQUEST['title'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
 
$send = is_valid_email($email);
If ($send)
{echo "true";}
else
{echo "false";}
 
if (!$email=="")
    {
        $sent = mail($to, $subject, $message, $headers) ;
        if($sent)
            {echo "<script>alert('your mail was sent successfully')</script>";} 
        else
            {print "We encountered an error sending your mail";}    
    }
 
?>

Re: Compilation failed: range out of order ...-Beginner question

Posted: Mon Nov 02, 2009 3:10 am
by Xrcr9709
Problem solved, the dash had to be escaped, which was not dont in the example I followed.