Email for validation

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
greg92
Forum Newbie
Posts: 3
Joined: Sat Jan 15, 2005 1:57 am

Email for validation

Post by greg92 »

I am trying to validate email addreses sent from a form. The trouble is , when I enter an invalid email address, I am not getting any error msg and the rest of the code is still being read.
How can I get this to work?
HTML:

Code: Select all

<FORM
 method='POST' action="contact001.php3" >


<TABLE border="0" cellpadding="2" cellspacing="2" > 
<TR>
    <TD>
   First Name:
    </TD>
    <TD>
   <INPUT type='text' name='FirstName' size='30' value=''>
    </TD>
</TR>
<TR>
    <TD>
   Email address:
    </TD>
    <TD>
   <INPUT type='text' name='Email' size='20' value=''>
    </TD>
</TR></table>
PHP:

Code: Select all

<?php

function validEmail($Email)  
&#123;  
$return = array();   
    if (!eregi("^&#1111;0-9a-z_](&#1111;-_.]?&#1111;0-9a-z])*@&#1111;0-9a-z]&#1111;-.0-9a-z]*\\.&#1111;a-z]&#123;2,4&#125;&#1111;.]?$",$Email, $check)) 
    &#123; 
        $return&#1111;"status"] = false;  
        $return&#1111;"msg"] = 'Error: Invalid e-mail address.';          
        return $return;  
    &#125;  
    $host = substr(strstr($check&#1111;0], '@'), 1); 
    if (!checkdnsrr($host.'.',"MX"))  
    &#123;
        $return&#1111;"status"] = false;  
        $return&#1111;"msg"] = 'Error: Invalid host';          
        return $return;  
    &#125;
    $return&#1111;"status"] = true;  
    $return&#1111;"msg"] = $Email;  
    return $return;  
&#125;

$message .= "First Name:$FirstName \n";
$message .= "Email:$Email \n"; 




PRINT "<p>Greetings $FirstName, <br><br>thank you using the my website to book your accomadation.
  We hope you will use our site again in the future.<br><br>";
print "If you have any ideas about how we can improve our website, feel free to email us at my@email.com.<br><br>Regards,<br><br>my company LTD.</p>";



mail("myemail@yahoo.com", "Booking from my website", "You have a villa booking made on the my websitewebsite: \n\n$message \n\n\n Contact: me@myemail.com\nTel:99999", "From: $Email" );





?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you don't appear to call the function..
greg92
Forum Newbie
Posts: 3
Joined: Sat Jan 15, 2005 1:57 am

Post by greg92 »

Sorry, I'm new at this PHP stuff, how would I do that? :idea:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

result = function_name(argument1, argument2, argument3, ...);
choco
Forum Newbie
Posts: 6
Joined: Sun Jan 23, 2005 6:55 am
Location: Behind the BenQ ;)

Post by choco »

If you're such a noob (no offence meant) directly you would type:

validEmail(webmaster@zelda-dimension.net);

...where you replace my e-mail (webmaster@ze...) with your e-mail testing. Another option with this is to create a form and to have a thing on your site where visitors can test whether any e-mail is active (this is what you would replace the above function call with:

validEmail($test);

...and you could use the form "GET" method to allow users to enter an e-mail to test. You can test it by typing in your browser (http://www.your-site.com/directory/scri ... st=<e-mail to be tested>).

I don't know if this makes any sense, hope it does ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

choco wrote:If you're such a noob (no offence meant) directly you would type:

validEmail(webmaster@zelda-dimension.net);
this throws a parse error.
validEmail($test);

...and you could use the form "GET" method to allow users to enter an e-mail to test. You can test it by typing in your browser (http://www.your-site.com/directory/scri ... st=<e-mail to be tested>).
this will only work if register globals is on.. and it shouldn't be. (security issue)
Post Reply