form mail email validation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George L
    Former vBulletin Support
    • May 2000
    • 32996
    • 3.8.x

    form mail email validation?

    Okay i am a php newbie and have been following tutorials on creating my own form mail for one of my sites... i have everything except email validation. How do i add email validation to the below script
    PHP Code:
    <?php

    $form 
    "
    <FORM METHOD=\"post\" ACTION=\"
    $PHP_SELF\">
    <p>Name: 
    <input type=\"text\" name=\"name\" value=\"
    $name\" size=\"30\">
    <br>
    Email: 
    <input type=\"text\" name=\"email\" value=\"
    $email\" size=\"30\">
    <br>
    </p>
    <p> 
    <textarea name=\"comments\" rows=\"12\" cols=\"45\" wrap=\"virtual\">
    $comments</textarea>
    </p>
    <p>                    
    <INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"check\">
    <INPUT TYPE=\"reset\" VALUE=\"reset\">
    <INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\"></p>
    </FORM>
    "
    ;

    if (
    $action != "check") {
    // show form
    echo "$form";
    } elseif (
    $action == "check") {

    $send "yes";

    if (
    $name == "") {
    $name_error "<br><b>Please enter name...</b><br>";
    $send "no";
    }

    if (
    $email == "") {
    $email_error "<b>Please enter email...</b><br>";
    $send "no";
    }

    if (
    $comments == "") {
    $comments_error "<b>Please enter a message...</b><br>";
    $send "no";
    }

    if (
    $send == "yes") {
    // okay to send
    $msg "Email sent from domain.com form\n\n";
    $msg .= "Sender's Name:    $name\n";
    $msg .= "Sender's Email:   $email\n";
    $msg .= "Message:          $comments\n";

    $to "[email protected]";
    $subject "Contact Form";
    $mailheaders "From: domain.com <> \n";
    $mailheaders .= "Reply: $email\n\n";
    // send email
    mail($to$subject$msg$mailheaders);
    echo 
    "<br><br>Mail has been sent. ";

    $msg2 "Email sent from domain.com form\n\n";
    $msg2 .= "Sender's Name:    $name\n";
    $msg2 .= "Sender's Email:   $email\n";
    $msg2 .= "Message:          $comments\n";
    $confirm "Copy of form email sent: domain.com";
    $mailheaders2 "From: domain.com <> \n";
    $mailheaders2 .= "Reply: $to\n\n";
    mail($email$confirm$msg2$mailheaders2);
    echo 
    "A copy has also been sent to your email";

    } elseif (
    $send == "no") {
    echo 
    "$name_error";
    echo 
    "$email_error";
    echo 
    "$comments_error";
    echo 
    "$form";
     }
    }
    ?>
    thanks
    :: Always Back Up Forum Database + Attachments BEFORE upgrading !
    :: Nginx SPDY SSL - World Flags Demo [video results]
    :: vBulletin hacked forums: Clean Up Guide for VPS/Dedicated hosting users [ vbulletin.com blog summary ]
  • Chen
    Senior Member
    • Jun 2001
    • 8388

    #2
    I swear to God I saw this somewhere on php.net's docs, it was contributed by a user, for it seems like they've emptied ALL of the comments. It is just me??

    See:

    No comments on strstr()??
    Last edited by Chen; Mon 24 Sep '01, 3:10am.
    Chen Avinadav
    Better to remain silent and be thought a fool than to speak out and remove all doubt.

    גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

    Comment

    • Scott MacVicar
      Former vBulletin Developer
      • Dec 2000
      • 13286

      #3
      PHP Code:
        if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$"$email)) {
          
      $email_error "Enter a valid email";
          
      $send "no";
        } 
      this should help hopefully it checks the username is valid that a @ is present and the domain is a valid format.
      Scott MacVicar

      My Blog | Twitter

      Comment

      • George L
        Former vBulletin Support
        • May 2000
        • 32996
        • 3.8.x

        #4
        thanks... i used
        PHP Code:
        //validate email
        if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$"$email)) {
        $email_error "<b>Please enter email and proper format...</b><br>";
        $send "no";

        works perfectly
        :: Always Back Up Forum Database + Attachments BEFORE upgrading !
        :: Nginx SPDY SSL - World Flags Demo [video results]
        :: vBulletin hacked forums: Clean Up Guide for VPS/Dedicated hosting users [ vbulletin.com blog summary ]

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...