help with email verification
Posted: Tue Jul 01, 2008 8:29 am
Im quite new with php and I need a little help. I have this code that verifies email and saves it into a database. My problem is after its verified the $email variable becomes empty and saves a blank("") in the email field in the database. Pls tell me what's wrong with the code. Any help would be very much appreciated.
Thanks,
Lscueto
<?
include "db.php";
$email=$_POST['email'];
function EmailValidation($email) {
$email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits
if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) ) { //checks to make sure the email address is in a valid format
$domain = explode( "@", $email ); //get the domain name
if ( @fsockopen ($domain[1],80,$errno,$errstr,3)) {
//if the connection can be established, the email address is probabley valid
return true;
/*
GENERATE A VERIFICATION EMAIL
*/
} else {
return false; //if a connection cannot be established return false
}
} else {
return false; //if email address is an invalid format return false
}
}
function EmailForm($email){
if(empty($_POST['email'])){
echo "<form action=".$_SERVER['PHP_SELF']." method='post'>
<table border='0'>
<tr>
<td>Email</td>
<td><input name='email' type='text' id='email' /></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='Submit' value='Subscribe' /></td>
</tr>
</table>
</form>";
} elseif(isset($_POST['email'])) {
if(EmailValidation($_POST['email'])) {
$sql=mysql_query("INSERT INTO mailinglist (email,date_joined) VALUES ('$email',now())")or die(mysql_error());
if(!$sql)
{
echo " Data not uploaded pls check your inputs";
}else{
echo " You are now subscribed";
}
} else {
echo "Your email address appears to be invalid. Please try again.";
}
} else {
echo "An error has occured, please contact the administrator.";
}
}
EmailForm();
?>
Thanks,
Lscueto
<?
include "db.php";
$email=$_POST['email'];
function EmailValidation($email) {
$email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits
if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) ) { //checks to make sure the email address is in a valid format
$domain = explode( "@", $email ); //get the domain name
if ( @fsockopen ($domain[1],80,$errno,$errstr,3)) {
//if the connection can be established, the email address is probabley valid
return true;
/*
GENERATE A VERIFICATION EMAIL
*/
} else {
return false; //if a connection cannot be established return false
}
} else {
return false; //if email address is an invalid format return false
}
}
function EmailForm($email){
if(empty($_POST['email'])){
echo "<form action=".$_SERVER['PHP_SELF']." method='post'>
<table border='0'>
<tr>
<td>Email</td>
<td><input name='email' type='text' id='email' /></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='Submit' value='Subscribe' /></td>
</tr>
</table>
</form>";
} elseif(isset($_POST['email'])) {
if(EmailValidation($_POST['email'])) {
$sql=mysql_query("INSERT INTO mailinglist (email,date_joined) VALUES ('$email',now())")or die(mysql_error());
if(!$sql)
{
echo " Data not uploaded pls check your inputs";
}else{
echo " You are now subscribed";
}
} else {
echo "Your email address appears to be invalid. Please try again.";
}
} else {
echo "An error has occured, please contact the administrator.";
}
}
EmailForm();
?>