Page 1 of 1
help with email verification?
Posted: Mon Dec 11, 2006 12:25 pm
by darkfreaks
hey my verification isnt working it just goes ahead and sends the email without checking it. could someone look over the code and properly tell me how to do the code? thanks
my code is:
Code: Select all
// check mail
function check_mail($email)
{
if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$",$email))
{
return true;
}
else
{
return false;
}
}
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }
?>
<input name="email" type="text" id="email"><?php echo $emailerror; ?>
[/syntax]
Posted: Mon Dec 11, 2006 12:26 pm
by Flamie
umm where do you call that function?
Posted: Mon Dec 11, 2006 12:38 pm
by darkfreaks
i put
Code: Select all
if ($email) == false { $emailerror = "error here";}
then i echoed the error next to the form and it doesnt do anything but send the email without checking it first?[/syntax]
Posted: Mon Dec 11, 2006 12:41 pm
by Flamie
Read the PHP manual on functions, when you create a function you need to "call it" for it to work
Code: Select all
if(check_mail($email) == false)
echo "bad email.<br>";
else
{
//do w/e you want with it
}
Posted: Mon Dec 11, 2006 1:08 pm
by darkfreaks
ok so i copied this code how would i make it so if it returned empty or not in the eregi pattern so it errored in the email form instead of just sending it plus erroring or just sending it?
Code: Select all
function ValidateMail($Email) {
$result = array();
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
$result[0]=false;
$result[1]="$Email is not properly formatted";
return $result;
}
}
Posted: Mon Dec 11, 2006 2:50 pm
by John Cartwright
darkfreaks wrote:Ok, so I copied this code. How would I make it so if it returned empty or not in the eregi pattern, so it would error in the email form instead of just sending it plus erroring?
Please use punctuation and proper grammar when possible, it took me 5 read overs to even understand what you said
Code: Select all
function ValidateMail($Email) {
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email);
}
if (ValidateMail($email)) {
echo 'Email has been sent';
mail( .. );
}
else
{
echo $email .' is not a valid address';
}