From: Markus Ernst on
Hello

This is actually not specifically a QuickForm question, but it is
related to this function I took from the QuickForm manual, and which is
actually built-in natively in QuickForm, too:

function checkEmail($email, $domainCheck = false)
{
if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
'\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
if ($domainCheck && function_exists('checkdnsrr')) {
list (, $domain) = explode('@', $email);
if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
return true;
}
return false;
}
return true;
}
return false;
}

Now it happend that the check for an e-mail address of the following
form returned false, although the address was claimed to be correct:

firstname.lastname(a)subdomain.maindomain.tld

So, both MX and A checks for subdomain.maindomain.tld returned false.
Performing the checks for maindomain.tld only, both returned true. So I
added a fix:

function checkEmail($email, $domainCheck = false)
{
if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
'\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
if ($domainCheck && function_exists('checkdnsrr')) {
list (, $domain) = explode('@', $email);
if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
return true;
}
// Fix: check with removed sub domains
$spl = explode(".", $domain);
$c = count($spl);
$domain = $spl[$c - 2] . "." . $spl[$c - 1];
if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
return true;
}
return false;
}
return true;
}
return false;
}

Now, I am not familiar with anything about MX and A records. Is this a
sensible fix, which should even make it into QuickForm(2)? Or is it
rather likely to introduce new problems I am not aware of? Thanks for
your comments.
From: James Collins on
Hi Markus,

Which operating system are you running your PHP code from?

According to http://php.net/manual/en/function.checkdnsrr.php, the function
might not exist if you're using Windows.

I do not have any specific experience with the checkEmail() or checkdnsrr()
functions, but I have successfully used PEAR's NET_DNS package (
http://pear.php.net/package/Net_DNS) for querying DNS records on both
windows and linux servers.

Regards,

James Collins



On 11 February 2010 00:47, Markus Ernst <derernst(a)gmx.ch> wrote:

> Hello
>
> This is actually not specifically a QuickForm question, but it is related
> to this function I took from the QuickForm manual, and which is actually
> built-in natively in QuickForm, too:
>
> function checkEmail($email, $domainCheck = false)
> {
> if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
> '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
> if ($domainCheck && function_exists('checkdnsrr')) {
> list (, $domain) = explode('@', $email);
> if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
> return true;
> }
> return false;
> }
> return true;
> }
> return false;
> }
>
> Now it happend that the check for an e-mail address of the following form
> returned false, although the address was claimed to be correct:
>
> firstname.lastname(a)subdomain.maindomain.tld
>
> So, both MX and A checks for subdomain.maindomain.tld returned false.
> Performing the checks for maindomain.tld only, both returned true. So I
> added a fix:
>
> function checkEmail($email, $domainCheck = false)
> {
> if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
> '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
> if ($domainCheck && function_exists('checkdnsrr')) {
> list (, $domain) = explode('@', $email);
> if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
> return true;
> }
> // Fix: check with removed sub domains
> $spl = explode(".", $domain);
> $c = count($spl);
> $domain = $spl[$c - 2] . "." . $spl[$c - 1];
> if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
> return true;
> }
> return false;
> }
> return true;
> }
> return false;
> }
>
> Now, I am not familiar with anything about MX and A records. Is this a
> sensible fix, which should even make it into QuickForm(2)? Or is it rather
> likely to introduce new problems I am not aware of? Thanks for your
> comments.
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
From: Mark Steudel on
Something else to try would be to test the subdomain with the
checkdnsrr function outside of that email function. Depending on how
DNS is setup, it's possible that the subdomain isn't actually an A
record but a CNAME and is therefore returning false. If you look at
the two checks, it only checks that it's a MX record or A record ...

Good Luck, Mark


On Wed, Feb 10, 2010 at 12:11 PM, James Collins <james(a)om4.com.au> wrote:
> Hi Markus,
>
> Which operating system are you running your PHP code from?
>
> According to http://php.net/manual/en/function.checkdnsrr.php, the function
> might not exist if you're using Windows.
>
> I do not have any specific experience with the checkEmail() or checkdnsrr()
> functions, but I have successfully used PEAR's NET_DNS package (
> http://pear.php.net/package/Net_DNS) for querying DNS records on both
> windows and linux servers.
>
> Regards,
>
> James Collins
>
>
>
> On 11 February 2010 00:47, Markus Ernst <derernst(a)gmx.ch> wrote:
>
>> Hello
>>
>> This is actually not specifically a QuickForm question, but it is related
>> to this function I took from the QuickForm manual, and which is actually
>> built-in natively in QuickForm, too:
>>
>> function checkEmail($email, $domainCheck = false)
>> {
>>    if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
>>                   '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
>>        if ($domainCheck && function_exists('checkdnsrr')) {
>>            list (, $domain)  = explode('@', $email);
>>            if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
>>                return true;
>>            }
>>            return false;
>>        }
>>        return true;
>>    }
>>    return false;
>> }
>>
>> Now it happend that the check for an e-mail address of the following form
>> returned false, although the address was claimed to be correct:
>>
>> firstname.lastname(a)subdomain.maindomain.tld
>>
>> So, both MX and A checks for subdomain.maindomain.tld returned false.
>> Performing the checks for maindomain.tld only, both returned true. So I
>> added a fix:
>>
>> function checkEmail($email, $domainCheck = false)
>> {
>>    if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
>>                   '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
>>        if ($domainCheck && function_exists('checkdnsrr')) {
>>            list (, $domain)  = explode('@', $email);
>>            if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
>>                return true;
>>            }
>>            // Fix: check with removed sub domains
>>            $spl = explode(".", $domain);
>>            $c = count($spl);
>>            $domain = $spl[$c - 2] . "." . $spl[$c - 1];
>>            if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
>>                return true;
>>            }
>>            return false;
>>        }
>>        return true;
>>    }
>>    return false;
>> }
>>
>> Now, I am not familiar with anything about MX and A records. Is this a
>> sensible fix, which should even make it into QuickForm(2)? Or is it rather
>> likely to introduce new problems I am not aware of? Thanks for your
>> comments.
>>
>> --
>> PEAR General Mailing List (http://pear.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>



--

-----------------------------------------
Mark Steudel
P: 206.375.7244
msteudel(a)gmail.com

.. : Work : .
http://www.mindfulinteractive.com

.. : Play : .
http://www.steudel.org/blog
From: Markus Ernst on
Mark Steudel schrieb:
> Something else to try would be to test the subdomain with the
> checkdnsrr function outside of that email function. Depending on how
> DNS is setup, it's possible that the subdomain isn't actually an A
> record but a CNAME and is therefore returning false. If you look at
> the two checks, it only checks that it's a MX record or A record ...

Thank you for this hint. I now tried checkdnsrr($domain, "CNAME"), which
returned false for both main domain and sub domain, and
checkdnsrr($domain) without the type argument, which behaves the same as
checking with "MX" and "A" type arguments.

It looks like in this special case, mails to addresses
*@subdomain.maindomain.tld are handled internally by the server at
maindomain.tld, without any handling at DNS level.
From: Ken Guest on
You could use the Validate package to determine whether an email
address is valid.
http://pear.php.net/manual/en/package.validate.validate.email.php


On Thu, Feb 11, 2010 at 11:15 AM, Markus Ernst <derernst(a)gmx.ch> wrote:
> Mark Steudel schrieb:
>>
>> Something else to try would be to test the subdomain with the
>> checkdnsrr function outside of that email function. Depending on how
>> DNS is setup, it's possible that the subdomain isn't actually an A
>> record but a CNAME and is therefore returning false. If you look at
>> the two checks, it only checks that it's a MX record or A record ...
>
> Thank you for this hint. I now tried checkdnsrr($domain, "CNAME"), which
> returned false for both main domain and sub domain, and checkdnsrr($domain)
> without the type argument, which behaves the same as checking with "MX" and
> "A" type arguments.
>
> It looks like in this special case, mails to addresses
> *@subdomain.maindomain.tld are handled internally by the server at
> maindomain.tld, without any handling at DNS level.
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
http://blogs.linux.ie/kenguest/