Invalid Email error?

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
youngloopy
Forum Newbie
Posts: 9
Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:

Invalid Email error?

Post by youngloopy »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Could someone look at my code and tell me why it keeps returning an invalid email when I have entered many valid emails and it still doesn't work.
Thanks,
-josh

Code: Select all

<?php

$dbh=mysql_connect ("localhost", "xxxxxx_xxxxxx", "xxxxxxxxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxxx_xxxxxx");
echo ("
<table width='100%' cellspacing='0' cellpadding='0' align='center'>
<tr>
");
if ($_POST[register]) {
$email = htmlspecialchars(strip_tags($_POST[email]));
$ip = $_SERVER['REMOTE_ADDR'];
if($email==NULL) {
echo ("
<td align='center'>
You must enter an Email!
</td>
");
}else{
function CheckMail($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 (!CheckMail($email)) {
echo("
<td align='center'>
That is not a valid Email.
</td>
");
}else{
$checkemail = mysql_num_rows(mysql_query("SELECT email FROM
maillist WHERE email='$email'"));
if ($checkemail>0) {
echo ("
<td align='center'>
You have already registered! Thank You!
</td>
");
}else{
$query = mysql_query("INSERT INTO maillist (email, ip) VALUES
('$email', '$ip')");
echo ("
<td align='center'>
Thank You!<br>
Your Email Has Been Submitted!</td>
");
}
}
}
}else{
echo ("
<form name='maillist' method='POST'>
<td align='center'>Newsletter Signup</td>
</tr>
<tr>
<td align='center'><input type='text' name='email' value='Your Email Address'></td>
</tr>
<tr>
<td align='center'><input name='register' type='submit' value='Register'></td>
</form>
");
}
echo ("
</tr>
</table>
");
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply