utils icon indicating copy to clipboard operation
utils copied to clipboard

Validators::isEmail: Add check for DNS nameservers.

Open janbarasek opened this issue 4 years ago • 8 comments

  • new feature
  • BC break? no

E-mail should be valid only in case of domain name use valid MX DNS record.

Examples:

Validators::isEmail('[email protected]'); // true
Validators::isEmail('[email protected]'); // true
Validators::isEmail('[email protected]', true); // false

janbarasek avatar Oct 12 '21 16:10 janbarasek

You don't need MX record. A, or AAAA is sufficient to deliver e-mails.

milo avatar Oct 12 '21 20:10 milo

Also I think checkdnsrr(idn_to_ascii($domain), 'MX')) should be used. checkdnsrr() returns bool and idn_to_ascii() is for domains like ñandu.cl (var_dump(checkdnsrr(idn_to_ascii('ñandu.cl'), 'MX'));)

Ideal would imho be to support only fully FQDN - if trailing dot is missing, add it. It should prevent multiple lookups with relative domain name. So instead of google.com, always look for google.com.

mabar avatar Oct 12 '21 20:10 mabar

Part after @ can be domain (MX is required), or hostname (one of MX, A, or AAAA is required). I think checking existence of MX or A or AAAA by checkdnsrr() is sufficient.

To IDN - yes, idn_to_ascii() shoud be used, but I'm not sure, default parameters are OK.

milo avatar Oct 13 '21 14:10 milo

@janbarasek can you update PR please?

dg avatar Oct 21 '21 11:10 dg

There was forum post about this 8 years ago https://forum.nette.org/en/1293-mail-adress-validation-mx-records and it contains good points which needs to be solved.

nechutny avatar Oct 21 '21 12:10 nechutny

I don't think so

  • check MX/A - yes, it will
  • it will be slower - yes, that's the price (surely few tens of ms, not seconds)
  • process MX records - no, thats what MTA will do
  • whois database - a little bit off topic

We only want to check that domain/hostname exists, not that they has correctly configured mail delivery. If domain/hostname is wrong, MTA fails immediately (that's what we want to prevent). If domain/hostname is correct, but MX records are incorrect or host is down, MTA will use queue and will try to deliver later.

milo avatar Oct 21 '21 13:10 milo

You don't need MX record. A, or AAAA is sufficient to deliver e-mails.

I just encountered case when it was not. Customer had domain with only MX for sending emails and no A or AAAA records.

mabar avatar Dec 21 '21 20:12 mabar

And the conclusion?

milo avatar Dec 21 '21 20:12 milo