summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortekimaki <will@tekimaki.com>2011-01-12 17:40:11 -0500
committertekimaki <will@tekimaki.com>2011-01-12 17:40:11 -0500
commitf8507f229fb9e82be10924fe025d0295a2eae746 (patch)
tree3698b1c3e0ad38a37f19cccf3b6efffdad38af36
parentc6d89deebeb60bb6283032af6436289168c1c4dc (diff)
downloadutil-f8507f229fb9e82be10924fe025d0295a2eae746.tar.gz
util-f8507f229fb9e82be10924fe025d0295a2eae746.tar.bz2
util-f8507f229fb9e82be10924fe025d0295a2eae746.zip
update is_email to 2.10.1
-rw-r--r--is_email.php164
1 files changed, 102 insertions, 62 deletions
diff --git a/is_email.php b/is_email.php
index 8af3247..3a29fbb 100644
--- a/is_email.php
+++ b/is_email.php
@@ -2,8 +2,8 @@
/**
* To validate an email address according to RFCs 5321, 5322 and others
*
- * Copyright (c) 2008-2010, Dominic Sayers <br>
- * Test schema documentation Copyright (c) 2010, Daniel Marschall <br>
+ * Copyright © 2008-2010, Dominic Sayers <br>
+ * Test schema documentation Copyright © 2010, Daniel Marschall <br>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@@ -34,18 +34,25 @@
* @copyright 2008-2010 Dominic Sayers
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://www.dominicsayers.com/isemail
- * @version 2.4.2 - Workaround PHP bug (http://bugs.php.net/48645) in test script
+ * @version 2.10.1 - Amended DNS lookup logic. Also, in is_email_statustext.php, changed $type to integer to allow for additional types (starting with SMTP codes)
*/
// The quality of this code has been improved greatly by using PHPLint
-// Copyright (c) 2009 Umberto Salsi
+// Copyright (c) 2010 Umberto Salsi
// This is free software; see the license for copying conditions.
// More info: http://www.icosaedro.it/phplint/
/*.
require_module 'standard';
require_module 'pcre';
.*/
-/*.mixed.*/ function is_email (/*.string.*/ $email, $checkDNS = false, $errorlevel = false) {
+/**
+ * Check that an email address conforms to RFCs 5321, 5322 and others
+ *
+ * @param string $email The email address to check
+ * @param boolean $checkDNS If true then a DNS check for A and MX records will be made
+ * @param mixed $errorlevel If true then return an integer error or warning number rather than true or false
+ */
+/*.mixed.*/ function is_email ($email, $checkDNS = false, $errorlevel = false) {
// Check that $email is a valid address. Read the following RFCs to understand the constraints:
// (http://tools.ietf.org/html/rfc5321)
// (http://tools.ietf.org/html/rfc5322)
@@ -61,10 +68,12 @@
// addresses at TLDs (e.g. johndoe@com), addresses with FWS and comments,
// addresses that are quoted and addresses that contain no alphabetic or
// numeric characters.
+ // true Same as E_ERROR
// false Return true for valid addresses, false for invalid ones. No warnings.
//
// Errors can be distinguished from warnings if ($return_value > ISEMAIL_ERROR)
// version 2.0: Enhance $diagnose parameter to $errorlevel
+// revision 2.5: some syntax changes to make it more PHPLint-friendly. Should be functionally identical.
if (!defined('ISEMAIL_VALID')) {
// No errors
@@ -94,7 +103,7 @@
define('ISEMAIL_EMPTYELEMENT' , 137);
define('ISEMAIL_UNESCAPEDSPECIAL' , 138);
define('ISEMAIL_LOCALTOOLONG' , 139);
- define('ISEMAIL_IPV4BADPREFIX' , 140);
+// define('ISEMAIL_IPV4BADPREFIX' , 140);
define('ISEMAIL_IPV6BADPREFIXMIXED' , 141);
define('ISEMAIL_IPV6BADPREFIX' , 142);
define('ISEMAIL_IPV6GROUPCOUNT' , 143);
@@ -108,19 +117,37 @@
define('ISEMAIL_IPV6SINGLECOLONSTART' , 151);
define('ISEMAIL_IPV6SINGLECOLONEND' , 152);
// Unexpected errors
- define('ISEMAIL_BADPARAMETER' , 190);
- define('ISEMAIL_NOTDEFINED' , 191);
+// define('ISEMAIL_BADPARAMETER' , 190);
+// define('ISEMAIL_NOTDEFINED' , 191);
// revision 2.1: Redefined unexpected error constants so they don't clash with the ISEMAIL_WARNING bit
+// revision 2.5: Undefined unused constants
}
- switch ($errorlevel) {
- case E_WARNING: $diagnose = true; $warn = true; break;
- case E_ERROR: $diagnose = true; $warn = false; break;
- case false: $diagnose = false; $warn = false; break;
- default: $diagnose = false; $warn = false;
+ if (is_bool($errorlevel)) {
+ if ((bool) $errorlevel) {
+ $diagnose = true;
+ $warn = false;
+ } else {
+ $diagnose = false;
+ $warn = false;
+ }
+ } else {
+ switch ((int) $errorlevel) {
+ case E_WARNING:
+ $diagnose = true;
+ $warn = true;
+ break;
+ case E_ERROR:
+ $diagnose = true;
+ $warn = false;
+ break;
+ default:
+ $diagnose = false;
+ $warn = false;
+ }
}
- $return_status = ($diagnose) ? ISEMAIL_VALID : true;
+ if ($diagnose) /*.mixed.*/ $return_status = ISEMAIL_VALID; else $return_status = true;
// version 2.0: Enhance $diagnose parameter to $errorlevel
// the upper limit on address lengths should normally be considered to be 254
@@ -133,16 +160,16 @@
// NB There is a mandatory 2-character wrapper round the actual address
$emailLength = strlen($email);
// revision 1.17: Max length reduced to 254 (see above)
- if ($emailLength > 254) return $diagnose ? ISEMAIL_TOOLONG : false; // Too long
+ if ($emailLength > 254) if ($diagnose) return ISEMAIL_TOOLONG; else return false; // Too long
// Contemporary email addresses consist of a "local part" separated from
// a "domain part" (a fully-qualified domain name) by an at-sign ("@").
// (http://tools.ietf.org/html/rfc3696#section-3)
$atIndex = strrpos($email,'@');
- if ($atIndex === false) return $diagnose ? ISEMAIL_NOAT : false; // No at-sign
- if ($atIndex === 0) return $diagnose ? ISEMAIL_NOLOCALPART : false; // No local part
- if ($atIndex === $emailLength - 1) return $diagnose ? ISEMAIL_NODOMAIN : false; // No domain part
+ if ($atIndex === false) if ($diagnose) return ISEMAIL_NOAT; else return false; // No at-sign
+ if ($atIndex === 0) if ($diagnose) return ISEMAIL_NOLOCALPART; else return false; // No local part
+ if ($atIndex === $emailLength - 1) if ($diagnose) return ISEMAIL_NODOMAIN; else return false; // No domain part
// revision 1.14: Length test bug suggested by Andrew Campbell of Gloucester, MA
// Sanitize comments
@@ -198,6 +225,8 @@
$localPart = substr($email, 0, $atIndex);
$domain = substr($email, $atIndex + 1);
$FWS = "(?:(?:(?:[ \\t]*(?:\\r\\n))?[ \\t]+)|(?:[ \\t]+(?:(?:\\r\\n)[ \\t]+)*))"; // Folding white space
+ $dotArray = /*. (array[]) .*/ array();
+
// Let's check the local part for RFC compliance...
//
// local-part = dot-atom / quoted-string / obs-local-part
@@ -205,11 +234,12 @@
// (http://tools.ietf.org/html/rfc5322#section-3.4.1)
//
// Problem: need to distinguish between "first.last" and "first"."last"
- // (i.e. one element or two). And I suck at regexes.
- $dotArray = /*. (array[int]string) .*/ preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $localPart);
+ // (i.e. one element or two). And I suck at regular expressions.
+ $dotArray = preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $localPart);
$partLength = 0;
- foreach ($dotArray as $element) {
+ foreach ($dotArray as $arrayMember) {
+ $element = (string) $arrayMember;
// Remove any leading or trailing FWS
$new_element = preg_replace("/^$FWS|$FWS\$/", '', $element);
if ($warn && ($element !== $new_element)) $return_status = ISEMAIL_FWS; // FWS is unlikely in the real world
@@ -217,8 +247,8 @@
// version 2.3: Warning condition added
$elementLength = strlen($element);
- if ($elementLength === 0) return $diagnose ? ISEMAIL_ZEROLENGTHELEMENT : false; // Can't have empty element (consecutive dots or dots at the start or end)
-// revision 1.15: Speed up the test and get rid of "unitialized string offset" notices from PHP
+ if ($elementLength === 0) if ($diagnose) return ISEMAIL_ZEROLENGTHELEMENT; else return false; // Can't have empty element (consecutive dots or dots at the start or end)
+// revision 1.15: Speed up the test and get rid of "uninitialized string offset" notices from PHP
// We need to remove any valid comments (i.e. those at the start or end of the element)
if ($element[0] === '(') {
@@ -227,7 +257,7 @@
$indexBrace = strpos($element, ')');
if ($indexBrace !== false) {
if (preg_match('/(?<!\\\\)[\\(\\)]/', substr($element, 1, $indexBrace - 1)) > 0)
- return $diagnose ? ISEMAIL_BADCOMMENT_START : false; // Illegal characters in comment
+ if ($diagnose) return ISEMAIL_BADCOMMENT_START; else return false; // Illegal characters in comment
$element = substr($element, $indexBrace + 1, $elementLength - $indexBrace - 1);
$elementLength = strlen($element);
}
@@ -239,7 +269,7 @@
$indexBrace = strrpos($element, '(');
if ($indexBrace !== false) {
if (preg_match('/(?<!\\\\)(?:[\\(\\)])/', substr($element, $indexBrace + 1, $elementLength - $indexBrace - 2)) > 0)
- return $diagnose ? ISEMAIL_BADCOMMENT_END : false; // Illegal characters in comment
+ if ($diagnose) return ISEMAIL_BADCOMMENT_END; else return false; // Illegal characters in comment
$element = substr($element, 0, $indexBrace);
$elementLength = strlen($element);
}
@@ -263,10 +293,10 @@
// version 2.0: Warning condition added
// Remove any FWS
$element = preg_replace("/(?<!\\\\)$FWS/", '', $element); // A warning condition, but we've already raised ISEMAIL_QUOTEDSTRING
- // My regex skillz aren't up to distinguishing between \" \\" \\\" \\\\" etc.
+ // My regular expression skills aren't up to distinguishing between \" \\" \\\" \\\\" etc.
// So remove all \\ from the string first...
$element = preg_replace('/\\\\\\\\/', ' ', $element);
- if (preg_match('/(?<!\\\\|^)["\\r\\n\\x00](?!$)|\\\\"$|""/', $element) > 0) return $diagnose ? ISEMAIL_UNESCAPEDDELIM : false; // ", CR, LF and NUL must be escaped
+ if (preg_match('/(?<!\\\\|^)["\\r\\n\\x00](?!$)|\\\\"$|""/', $element) > 0) if ($diagnose) return ISEMAIL_UNESCAPEDDELIM; else return false; // ", CR, LF and NUL must be escaped
// version 2.0: allow ""@example.com because it's technically valid
} else {
// Unquoted string tests:
@@ -277,7 +307,7 @@
//
// A zero-length element implies a period at the beginning or end of the
// local part, or two periods together. Either way it's not allowed.
- if ($element === '') return $diagnose ? ISEMAIL_EMPTYELEMENT : false; // Dots in wrong place
+ if ($element === '') if ($diagnose) return ISEMAIL_EMPTYELEMENT; else return false; // Dots in wrong place
// Any ASCII graphic (printing) character other than the
// at-sign ("@"), backslash, double quote, comma, or square brackets may
@@ -286,12 +316,12 @@
// (http://tools.ietf.org/html/rfc3696#section-3)
//
// Any excluded characters? i.e. 0x00-0x20, (, ), <, >, [, ], :, ;, @, \, comma, period, "
- if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]/', $element) > 0) return $diagnose ? ISEMAIL_UNESCAPEDSPECIAL : false; // These characters must be in a quoted string
+ if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]/', $element) > 0) if ($diagnose) return ISEMAIL_UNESCAPEDSPECIAL; else return false; // These characters must be in a quoted string
if ($warn && (preg_match('/^\\w+/', $element) === 0)) $return_status = ISEMAIL_UNLIKELYINITIAL; // First character is an odd one
}
}
- if ($partLength > 64) return $diagnose ? ISEMAIL_LOCALTOOLONG : false; // Local part must be 64 characters or less
+ if ($partLength > 64) if ($diagnose) return ISEMAIL_LOCALTOOLONG; else return false; // Local part must be 64 characters or less
// Now let's check the domain part...
@@ -307,6 +337,8 @@
$groupMax = 8;
// revision 2.1: new IPv6 testing strategy
$matchesIP = array();
+ $colon = ':'; // Revision 2.7: Daniel Marschall's new IPv6 testing strategy
+ $double_colon = '::';
// Extract IPv4 part from the end of the address-literal (if there is one)
if (preg_match('/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/', $addressLiteral, $matchesIP) > 0) {
@@ -314,13 +346,13 @@
if ($index === 0) {
// Nothing there except a valid IPv4 address, so...
- return ($diagnose) ? $return_status : true;
+ if ($diagnose) return $return_status; else return true;
// version 2.0: return warning if one is set
} else {
//- // Assume it's an attempt at a mixed address (IPv6 + IPv4)
-//- if ($addressLiteral[$index - 1] !== ':') return $diagnose ? ISEMAIL_IPV4BADPREFIX : false; // Character preceding IPv4 address must be ':'
+//- if ($addressLiteral[$index - 1] !== $colon) if ($diagnose) return ISEMAIL_IPV4BADPREFIX; else return false; // Character preceding IPv4 address must be ':'
// revision 2.1: new IPv6 testing strategy
- if (substr($addressLiteral, 0, 5) !== 'IPv6:') return $diagnose ? ISEMAIL_IPV6BADPREFIXMIXED : false; // RFC5321 section 4.1.3
+ if (substr($addressLiteral, 0, 5) !== 'IPv6:') if ($diagnose) return ISEMAIL_IPV6BADPREFIXMIXED; else return false; // RFC5321 section 4.1.3
//-
//- $IPv6 = substr($addressLiteral, 5, ($index === 7) ? 2 : $index - 6);
//- $groupMax = 6;
@@ -329,39 +361,35 @@
}
} else {
// It must be an attempt at pure IPv6
- if (substr($addressLiteral, 0, 5) !== 'IPv6:') return $diagnose ? ISEMAIL_IPV6BADPREFIX : false; // RFC5321 section 4.1.3
+ if (substr($addressLiteral, 0, 5) !== 'IPv6:') if ($diagnose) return ISEMAIL_IPV6BADPREFIX; else return false; // RFC5321 section 4.1.3
$IPv6 = substr($addressLiteral, 5);
//- $groupMax = 8;
// revision 2.1: new IPv6 testing strategy
}
-//echo "\n<br /><pre>\$IPv6 = $IPv6</pre>\n"; // debug
- $groupCount = preg_match_all('/^[0-9a-fA-F]{0,4}|\\:[0-9a-fA-F]{0,4}|(.)/', $IPv6, $matchesIP);
- $index = strpos($IPv6,'::');
-//echo "\n<br /><pre>\$matchesIP[0] = " . var_export($matchesIP[0], true) . "</pre>\n"; // debug
+ $matchesIP = explode($colon, $IPv6); // Revision 2.7: Daniel Marschall's new IPv6 testing strategy
+ $groupCount = count($matchesIP);
+ $index = strpos($IPv6,$double_colon);
+
if ($index === false) {
// We need exactly the right number of groups
- if ($groupCount !== $groupMax) return $diagnose ? ISEMAIL_IPV6GROUPCOUNT : false; // RFC5321 section 4.1.3
+ if ($groupCount !== $groupMax) if ($diagnose) return ISEMAIL_IPV6GROUPCOUNT; else return false; // RFC5321 section 4.1.3
} else {
- if ($index !== strrpos($IPv6,'::')) return $diagnose ? ISEMAIL_IPV6DOUBLEDOUBLECOLON : false; // More than one '::'
+ if ($index !== strrpos($IPv6,$double_colon)) if ($diagnose) return ISEMAIL_IPV6DOUBLEDOUBLECOLON; else return false; // More than one '::'
if ($index === 0 || $index === (strlen($IPv6) - 2)) $groupMax++; // RFC 4291 allows :: at the start or end of an address with 7 other groups in addition
-//echo "\n<br /><pre>\$groupMax = $groupMax</pre>\n"; // debug
- if ($groupCount > $groupMax) return $diagnose ? ISEMAIL_IPV6TOOMANYGROUPS : false; // Too many IPv6 groups in address
+ if ($groupCount > $groupMax) if ($diagnose) return ISEMAIL_IPV6TOOMANYGROUPS; else return false; // Too many IPv6 groups in address
if ($groupCount === $groupMax) $return_status = ISEMAIL_SINGLEGROUPELISION; // Eliding a single group with :: is deprecated by RFCs 5321 & 5952
}
// Check for single : at start and end of address
- if (($matchesIP[0][0] === '') && ($matchesIP[0][1] !== ':')) return $diagnose ? ISEMAIL_IPV6SINGLECOLONSTART : false; // Address starts with a single colon
- if (($matchesIP[0][$groupCount - 1] === ':') && ($matchesIP[0][$groupCount - 2] !== ':')) return $diagnose ? ISEMAIL_IPV6SINGLECOLONEND : false; // Address ends with a single colon
+ // Revision 2.7: Daniel Marschall's new IPv6 testing strategy
+ if ((substr($IPv6, 0, 1) === $colon) && (substr($IPv6, 1, 1) !== $colon)) if ($diagnose) return ISEMAIL_IPV6SINGLECOLONSTART; else return false; // Address starts with a single colon
+ if ((substr($IPv6, -1) === $colon) && (substr($IPv6, -2, 1) !== $colon)) if ($diagnose) return ISEMAIL_IPV6SINGLECOLONEND; else return false; // Address ends with a single colon
// Check for unmatched characters
- array_multisort($matchesIP[1], SORT_DESC);
- if ($matchesIP[1][0] !== '') {
-//echo "\n<br /><pre>\$matchesIP[1] = " . var_export($matchesIP[1], true) . "</pre>\n"; // debug
- return $diagnose ? ISEMAIL_IPV6BADCHAR : false; // Illegal characters in address
-} // debug
+ if (count(preg_grep('/^[0-9A-Fa-f]{0,4}$/', $matchesIP, PREG_GREP_INVERT)) !== 0) if ($diagnose) return ISEMAIL_IPV6BADCHAR; else return false; // Illegal characters in address
// It's a valid IPv6 address, so...
- return ($diagnose) ? $return_status : true;
+ if ($diagnose) return $return_status; else return true;
// revision 2.1: bug fix: now correctly return warning status
} else {
// It's a domain name...
@@ -389,7 +417,7 @@
//
// RFC5321 precludes the use of a trailing dot in a domain name for SMTP purposes
// (http://tools.ietf.org/html/rfc5321#section-4.1.2)
- $dotArray = /*. (array[int]string) .*/ preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $domain);
+ $dotArray = preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $domain);
$partLength = 0;
$element = ''; // Since we use $element after the foreach loop let's make sure it has a value
// revision 1.13: Line above added because PHPLint now checks for Definitely Assigned Variables
@@ -397,7 +425,8 @@
if ($warn && (count($dotArray) === 1)) $return_status = ISEMAIL_TLD; // The mail host probably isn't a TLD
// version 2.0: downgraded to a warning
- foreach ($dotArray as $element) {
+ foreach ($dotArray as $arrayMember) {
+ $element = (string) $arrayMember;
// Remove any leading or trailing FWS
$new_element = preg_replace("/^$FWS|$FWS\$/", '', $element);
if ($warn && ($element !== $new_element)) $return_status = ISEMAIL_FWS; // FWS is unlikely in the real world
@@ -408,8 +437,8 @@
// Each dot-delimited component must be of type atext
// A zero-length element implies a period at the beginning or end of the
// local part, or two periods together. Either way it's not allowed.
- if ($elementLength === 0) return $diagnose ? ISEMAIL_DOMAINEMPTYELEMENT : false; // Dots in wrong place
-// revision 1.15: Speed up the test and get rid of "unitialized string offset" notices from PHP
+ if ($elementLength === 0) if ($diagnose) return ISEMAIL_DOMAINEMPTYELEMENT; else return false; // Dots in wrong place
+// revision 1.15: Speed up the test and get rid of "uninitialized string offset" notices from PHP
// Then we need to remove all valid comments (i.e. those at the start or end of the element
if ($element[0] === '(') {
@@ -418,7 +447,7 @@
$indexBrace = strpos($element, ')');
if ($indexBrace !== false) {
if (preg_match('/(?<!\\\\)[\\(\\)]/', substr($element, 1, $indexBrace - 1)) > 0)
- return $diagnose ? ISEMAIL_BADCOMMENT_START : false; // Illegal characters in comment
+ if ($diagnose) return ISEMAIL_BADCOMMENT_START; else return false; // Illegal characters in comment
// revision 1.17: Fixed name of constant (also spotted by turboflash - thanks!)
$element = substr($element, $indexBrace + 1, $elementLength - $indexBrace - 1);
$elementLength = strlen($element);
@@ -431,7 +460,7 @@
$indexBrace = strrpos($element, '(');
if ($indexBrace !== false) {
if (preg_match('/(?<!\\\\)(?:[\\(\\)])/', substr($element, $indexBrace + 1, $elementLength - $indexBrace - 2)) > 0)
- return $diagnose ? ISEMAIL_BADCOMMENT_END : false; // Illegal characters in comment
+ if ($diagnose) return ISEMAIL_BADCOMMENT_END; else return false; // Illegal characters in comment
// revision 1.17: Fixed name of constant (also spotted by turboflash - thanks!)
$element = substr($element, 0, $indexBrace);
$elementLength = strlen($element);
@@ -453,7 +482,7 @@
// separated by dots, and with a maximum total of 255
// octets.
// (http://tools.ietf.org/html/rfc1123#section-6.1.3.5)
- if ($elementLength > 63) return $diagnose ? ISEMAIL_DOMAINELEMENTTOOLONG : false; // Label must be 63 characters or less
+ if ($elementLength > 63) if ($diagnose) return ISEMAIL_DOMAINELEMENTTOOLONG; else return false; // Label must be 63 characters or less
// Any ASCII graphic (printing) character other than the
// at-sign ("@"), backslash, double quote, comma, or square brackets may
@@ -466,24 +495,35 @@
// (http://tools.ietf.org/html/rfc3696#section-2)
//
// Any excluded characters? i.e. 0x00-0x20, (, ), <, >, [, ], :, ;, @, \, comma, period, "
- if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]|^-|-$/', $element) > 0) return $diagnose ? ISEMAIL_DOMAINBADCHAR : false; // Illegal character in domain name
+ if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]|^-|-$/', $element) > 0) if ($diagnose) return ISEMAIL_DOMAINBADCHAR; else return false; // Illegal character in domain name
}
- if ($partLength > 255) return $diagnose ? ISEMAIL_DOMAINTOOLONG : false; // Domain part must be 255 characters or less (http://tools.ietf.org/html/rfc1123#section-6.1.3.5)
+ if ($partLength > 255) if ($diagnose) return ISEMAIL_DOMAINTOOLONG; else return false; // Domain part must be 255 characters or less (http://tools.ietf.org/html/rfc1123#section-6.1.3.5)
if ($warn && (preg_match('/^[0-9]+$/', $element) > 0)) $return_status = ISEMAIL_TLDNUMERIC; // TLD probably isn't all-numeric (http://www.apps.ietf.org/rfc/rfc3696.html#sec-2)
// version 2.0: Downgraded to a warning
// Check DNS?
if ($diagnose && ($return_status === ISEMAIL_VALID) && $checkDNS && function_exists('checkdnsrr')) {
- if (!(checkdnsrr($domain, 'A'))) $return_status = ISEMAIL_DOMAINNOTFOUND; // 'A' record for domain can't be found
- if (!(checkdnsrr($domain, 'MX'))) $return_status = ISEMAIL_MXNOTFOUND; // 'MX' record for domain can't be found
+ // Revision 2.10: Amended DNS logic
+ // An A-record is not required unless there are no MX-records
+ // for a domain. Obvious when you think about it.
+ // (http://tools.ietf.org/html/rfc5321#section-5)
+ // (http://tools.ietf.org/html/rfc2181#section-10.3)
+ // (http://tools.ietf.org/html/rfc1035)
+ if (!(checkdnsrr($domain, 'MX'))) {
+ $result = @dns_get_record($domain, DNS_A);
+
+ if ((is_bool($result) && !(bool) $result))
+ $return_status = ISEMAIL_DOMAINNOTFOUND; // Neither MX- nor A-record for domain can be found
+ else $return_status = ISEMAIL_MXNOTFOUND; // MX-record for domain can't be found
+ }
}
}
// Eliminate all other factors, and the one which remains must be the truth.
// (Sherlock Holmes, The Sign of Four)
- return ($diagnose) ? $return_status : true;
+ if ($diagnose) return $return_status; else return true;
// version 2.0: return warning if one is set
}
?>