NickG21
12-27-2006, 01:46 PM
hey everyone, below is my code for an e-mail validation script i am working on. i am very new to php and have developed this through the use of other threads on forums and tutorials i have found online. if anyone could tell me what is wrong about it i would appreciate it. there are no errors being generated for the php syntax but the code doesn't access the DNS and display whether the e-mail address is really valid or not. thank you
nick
<?php
function checkEmail($email)
{
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+([a-zA-Z0-9\._-] +)+$/" , $email)) {
return false;
}
list($username,$domain) = split('@',$email);
$mxhosts = array();
if(!getmcxrr($domain, $mxhosts)) {
if(!fsockopen($domain, 25, $errno, $errstr, 30))
{
return false;
}else{
foreach($mxhosts as $host) {
if (fsockopen($host,25,$errno,$errstr,30)) {
return true;
}
}
return false;
}
}
if(!fsockopen($domain,25,$errno,$errstr,30)) {
return false;
}else{
return true;
}
}
if (isset($_POST['submit'])) {
$email = trim($_POST['email']);
if(!checkEmail($email)) {
echo 'Invalid email address!';
}
else {
echo 'Email address is valid';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="emailcheck.php">
<table class="qForm">
<tr>
<td><a>Email:</a></td>
<td><input type="text" size="28" name=email value-<? echo"$email"?>"><br/></td>
</tr>
<tr>
<input type="hidden" value="1"
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
nick
<?php
function checkEmail($email)
{
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+([a-zA-Z0-9\._-] +)+$/" , $email)) {
return false;
}
list($username,$domain) = split('@',$email);
$mxhosts = array();
if(!getmcxrr($domain, $mxhosts)) {
if(!fsockopen($domain, 25, $errno, $errstr, 30))
{
return false;
}else{
foreach($mxhosts as $host) {
if (fsockopen($host,25,$errno,$errstr,30)) {
return true;
}
}
return false;
}
}
if(!fsockopen($domain,25,$errno,$errstr,30)) {
return false;
}else{
return true;
}
}
if (isset($_POST['submit'])) {
$email = trim($_POST['email']);
if(!checkEmail($email)) {
echo 'Invalid email address!';
}
else {
echo 'Email address is valid';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="emailcheck.php">
<table class="qForm">
<tr>
<td><a>Email:</a></td>
<td><input type="text" size="28" name=email value-<? echo"$email"?>"><br/></td>
</tr>
<tr>
<input type="hidden" value="1"
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>