I'm working on a mass e-mailer script for my site and I can't seem to get this one little thing to work.
I have 4 users:
1 with yahoo, one with a co.cc domain, one with a non existent domain and another with Gmail.
It sends to the co.cc and the non existent domains. The other two I have opted out.
I want it to send to the co.cc because it is valid, and not the non existent one because it's not valid But it's not working. Can anyone help?
I have 4 users:
1 with yahoo, one with a co.cc domain, one with a non existent domain and another with Gmail.
It sends to the co.cc and the non existent domains. The other two I have opted out.
I want it to send to the co.cc because it is valid, and not the non existent one because it's not valid But it's not working. Can anyone help?
PHP:
function _validate_mail($email)
{
// First, we check that there's one @ symbol,
// and that the lengths are right.
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
?'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
// Check if domain is IP. If not,
// it should be valid domain name
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
?([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
$isco_cc = (stristr($email_array[1],'.co.cc')) ? true : false;
if(!$this->checkDomain($email_array[1],$isco_cc)){
return false;
}else{
return true;
}
}
function checkDomain($domain, $iscocc = false)
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "mail_checker",
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
if($iscocc){
$url = "http://".$domain;
}else{
$url = "http://www.whois.net/getNB.cfm?domain_name=".$domain;
}
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
if(!preg_match("/\b(a|A)vailable\b/",$content)):
return true;
else:
return false;
endif;
}
Last edited: