Include your file first, then run the function on each itteration through your returned rows:
<?php
include_once('validation.php');
$validEmail = new emailValidate();
$result = sql_query("select email from mailing where groupid=$id") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$email = $row[0]; // If you want to use the textual key, use $row['email']; (note the quotes)
$validEmail->setEmail($email);
if($validEmail->checkEmailString())
{
if($validEmail->checkEmailDNS())
echo $email.' is a valid email address.<br>';
else
echo $email.' does not pass DNS validation.<br>';
}
else
echo $email.' is a malformed email address.<br>';
}
?>
Now, your class should reference the global variable $email using the syntax: $this->email.
Plus I added a new method called setEmail($email) which sets the global email. Just so you know. Here's how my class would be set up:
class emailValidate {
//set us up the class variables
var $email;
function setEmail($email)
{
$this->email = $email;
}
//1.Validate the string given as an email address to make sure it matches the form name@domainname
function checkEmailstring()
{
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $this->email))
return true;
else
return false;
}
//2.Validate the DNS MX record that the domain exists and has valid MX records.
function checkEmailDNS()
{
if($this->checkEmailString())
{
list($username,$domain)=split('@',$this->email);
if(checkdnsrr($domain,'MX'))
return true;
else
return false;
}
else
return false;
}
}
That class would make much more sense 😉 And much more resuable in more cases.