Hi internals,
I would like to gather feedback before drafting an RFC for a small addition
to PHP's DNS functions:
dns_check_mx(string $hostname): bool
The function would check whether a hostname has at least one non-null MX
record.
Today, checkdnsrr($domain, "MX") correctly returns true for a domain
publishing a Null MX record:
example.com. IN MX 0 .
This is correct, since an MX record exists. However, RFC 7505 (
https://www.rfc-editor.org/rfc/rfc7505.html) defines this as an explicit
signal that the domain does not accept email.
I am not proposing any change to checkdnsrr(). It should remain a low-level
DNS record existence check.
Proposed behavior:
- false when there are no MX records;
- false when all MX records are Null MX records;
- true when at least one MX record has an exchange target other than ".".
This would not validate email deliverability or perform SMTP-level checks.
It would only provide a DNS-level distinction between "has an MX record"
and "has a non-null MX record".
If there is interest in this direction, I am willing to work on the RFC and
implementation.
I would appreciate feedback on the scope, naming, and edge cases before
preparing an RFC.
Regards,
Samuel Fontebasso
Am 13.05.2026 um 03:47 schrieb Samuel Fontebasso samuel.txd@gmail.com:
I would like to gather feedback before drafting an RFC for a small addition to PHP's DNS functions:
dns_check_mx(string $hostname): boolThe function would check whether a hostname has at least one non-null MX record.
Proposed behavior:
- false when there are no MX records;
- false when all MX records are Null MX records;
- true when at least one MX record has an exchange target other than ".".
Am I correct that this would be equivalent to the following (example.com http://example.com/ return empty string "" for MX, not a dot ".")?
array_any(
dns_get_record($hostname, DNS_MX),
fn($r) => $r["target"]
)
I'm torn between providing in-core helper functions for common problems (and getmxrr/dns_get_mx is indeed misleading/annoying with its bool return value) but on the other hand I'm not sure checking for an MX is something usually done by the general developer. This sounds more like part of a library/framework as there are further complications when trying to determine about the ability to send email to an address.
Because of this I'd probably not add another helper function and try to handle it on the documentation level instead.
Regards,
- Chris