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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Xrcr9709
Forum Newbie
Posts: 2
Joined: Mon Nov 02, 2009 2:14 am

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

Post 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";}    
    }
 
?>
Xrcr9709
Forum Newbie
Posts: 2
Joined: Mon Nov 02, 2009 2:14 am

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

Post by Xrcr9709 »

Problem solved, the dash had to be escaped, which was not dont in the example I followed.
Post Reply