help with email verification?

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
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

help with email verification?

Post 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]
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

umm where do you call that function?
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post 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]
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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
}
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post 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; 
    } 
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 8O

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';
}
Post Reply