How to validate an e-mail form with PHP?

Discussion in 'PHP' started by eritrea1, Jun 23, 2012.

  1. #1
    This question, probably has been asked a thousand times, but upon searching i found one function to check e-mail form and so-far this is what i got.

    
    
    
    if(isset($_POST['mail'])){@$mail = $_POST['mail'];
    
    if(empty($mail))
    {echo 'Please Post your mail ID';}else {
    
    
    if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)*.([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $mail)) { echo 'false'; }else{ $record = 'MX'; list($user,$domain) = split('@',$mail); if(!checkdnsrr($domain,$record)){ echo 'false'; }else{ echo 'true';
     } }
    }}
    PHP:
    The problem with the code above is, that:

    When you try, to submit the form without writing an email, it says " Please Post your mail ID " As, it should but when you post an email Ex: then it says

    Deprecated: Function split() is deprecated in C:\xampp\htdocs\DIRECTORY\Library\test\register.php on line 53

    --I guess what i am looking for, is the un-deprecated form of the split function and probably adjust and check out the function it if has no flaws.

    Thanks.
     
    Solved! View solution.
    eritrea1, Jun 23, 2012 IP
  2. Dino1221

    Dino1221 Well-Known Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    101
    #2
    Dino1221, Jun 23, 2012 IP
  3. eritrea1

    eritrea1 Active Member

    Messages:
    182
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    70
    #3
    Well, great but not really. Because, i just did that, and i got.

    
     [B]Warning: preg_split() [[URL="http://localhost/directory/Library/test/function.preg-split"][COLOR=#0000ff]function.preg-split[/COLOR][/URL]]: No ending delimiter '@' found in [B]C:\xampp\htdocs\DIRECTORY\Library\test\register.php on line [B]53[/B][/B][/B]
    
    Code (markup):
     
    eritrea1, Jun 23, 2012 IP
  4. #4
    
    preg_split('/@/',$mail)
    
    PHP:
    ?
     
    Dino1221, Jun 23, 2012 IP
  5. eritrea1

    eritrea1 Active Member

    Messages:
    182
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    70
    #5
    Kisses and Hugs. Thanks Dino. It gave me, a 'true' response i will try to finish the user registration form now.
     
    eritrea1, Jun 23, 2012 IP