Jitterbug
March 25th, 2009, 06:07 AM
I have apache server and php-mailer that sends mails to addresses that it picks up from a MySQL databasehttp://images.intellitxt.com/ast/adTypes/mag-glass_10x10.gif (http://forums.devshed.com/#). What I'm trying to do, is that if some mail is returned as undelivered that address in database is invalid, so it should be marked as 'offline'. So the mailer wouldn't send any new messages to that address. Before I can do this I need to know if some email(s) are returned as undelivered.
How could I get information about undelivered mails? With 'reply to' and 'return path' in the headers?
And how could I automaticly update thease bad addresses to offline in mysql database? In other words, which is the best way to handle all undelivered mails?
NeoDreamer
March 26th, 2009, 03:14 PM
You can test if the email is in valid form and if the domain exists with this function. Of course, you can fake an email with a real domain, but this makes it harder for bad emails to be submitted.
As for detecting if the email is really real - I don't know.
// ================================================
// emailIsValid
// args: string - proposed email address
// ret: bool
// about: tells you if an email is in the correct
// form or not
function emailIsValid($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.