Results 1 to 6 of 6

Thread: valdate email in php form

Hybrid View

  1. #1

    valdate email in php form

    hi,

    i've used the form off the tutorial section and i'm trying to add a validate on the email. i have the follow code but i'm not sure where to place it. if anyone can have a look through this and tell me what to do

    PHP Code:
    function checkemail($first)
             {
             if
     (
    ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_
     `a-z{|}~]+\.'
    .'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$'$first))
                return 
    true;
             else
                return 
    false;
             } 
    this is the php code for the mailform

    PHP Code:
    <?PHP 
    $to 
    "info@garethflavell.co.uk"
    $subject "Results from your Request Info form";
    $headers "From: Form Mailer";
    $forward 0;
    $location "";

    $date date ("l, F jS, Y"); 
    $time date ("h:i A"); 



    $msg "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"

    if (
    $_SERVER['REQUEST_METHOD'] == "POST") {
        foreach (
    $_POST as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }
    else {
        foreach (
    $_GET as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }

    mail($to$subject$msg$headers); 
    if (
    $forward == 1) { 
        
    header ("Location:$location"); 

    else { 
        echo 
    "Thank you for submitting our form."


    ?>
    and this is my html code

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="styles/midori.css" rel="stylesheet" type="text/css">
    </head>

    <body leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0">
    <table width="369" height="164" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="24" height="1"><img src="images/spacer.gif" width="24" height="1"></td>
    <td width="345"><img src="images/spacer.gif" width="344" height="1"></td>
    </tr>
    <tr>
    <td height="13" background="images/hor.gif"><img src="images/spacer.gif" width="24" height="13"></td>
    <td bgcolor="E8E8E8" class="verdana10">Contact</td>
    </tr>
    <tr>
    <td rowspan="2">&nbsp;</td>
    <td height="7"><img src="images/spacer.gif" width="1" height="7"></td>
    </tr>
    <tr>
    <td height="143"><table width="344" height="143" border="0" cellpadding="0" cellspacing="0">
    <form action="mailer.php" method="post">
    <tr>
    <td width="70" height="22" class="form">Name</td>
    <td width="117" align="right"><input name="test" type="text" size="14"></td>
    <td width="46" class="form">Email</td>
    <td width="111" align="right"><input name="email" type="text" size="15"></td>
    </tr>
    <tr>
    <td height="102" align="left" valign="top"><table width="61" height="38" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="71" height="22" class="form">Message</td>
    </tr>
    <tr>
    <td height="19">&nbsp;</td>
    </tr>
    </table></td>
    <td colspan="3" align="right"><textarea name="message" cols="31" rows="5" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
    <td height="19">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right"><input name="submit" type="image" id="submit" src="images/submit.gif" width="38" height="16" border="0"></td>
    </tr>
    </form>
    </table></td>
    </tr>
    </table>

    </body>
    </html>


    any help is much appricated

  2. #2
    Place the function in mail.php.

    PHP Code:
    <?PHP
    function checkemail($first)
             {
             if
     (
    ereg('^[-!#$%&'*+./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!\#$%&'*+\/0-9=?A-Z^_
     
    `a-z{|}~]+.'.'[-!\#$%&'*+\./0-9=?A-Z^_`a-z{|}~]+$', $first))
                
    return true;
             else
                return 
    false;
             }


    $to "info@garethflavell.co.uk"
    $subject "Results from your Request Info form";
    $headers "From: Form Mailer";
    $forward 0;
    $location "";

    $date date ("l, F jS, Y"); 
    $time date ("h:i A"); 



    $msg "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"

    if (
    $_SERVER['REQUEST_METHOD'] == "POST") {

        if(!
    checkemail($_POST['email'])){
             echo 
    "Your email address is invalid";
             exit;
        }

        foreach (
    $_POST as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }
    else {

        if(!
    checkemail($_GET['email'])){
             echo 
    "Your email address is invalid";
             exit;
        }

        foreach (
    $_GET as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }

    mail($to$subject$msg$headers); 
    if (
    $forward == 1) { 
        
    header ("Location:$location"); 

    else { 
        echo 
    "Thank you for submitting our form."


    ?>
    Look at yourself in the mirror and ask... have I met you before?

  3. #3
    do i have to do anything else, like place something in the html?because it isn't working at he moment.

  4. #4
    is it giving any error message?
    Look at yourself in the mirror and ask... have I met you before?

  5. #5
    i've changed the validation, and gone for javascript but thanks for your help again

  6. #6
    anytime
    Look at yourself in the mirror and ask... have I met you before?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012