#48951 closed feature request (worksforme)
email_too_short is not good email validation candidate
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | low | |
| Severity: | trivial | Version: | 5.4 |
| Component: | Keywords: | 2nd-opinion | |
| Focuses: | Cc: |
Description
Currently, both is_email and sanitize_email will invalidate/sanitize valid emails:
'admin@mailserver1'
'm@m'
Both are valid emails. ICANN just discourages using them.
The problem comes when you work with decoupled WordPress, and the front end is using custom validation that allows such emails, but WordPress doesn't so you don't have consistent behavior. Plus this is just wrong, as the official specification allows such mails.
https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses
Change History (4)
#2
@
5 years ago
- Priority changed from normal to low
- Severity changed from normal to trivial
- Type changed from defect (bug) to feature request
#3
@
4 months ago
- Resolution set to worksforme
- Status changed from new to closed
The problem comes when you work with decoupled WordPress, and the front end is using custom validation that allows such emails, but WordPress doesn't so you don't have consistent behavior. Plus this is just wrong, as the official specification allows such mails.
This is correct, despite ICANN discourages the use of no dot domains, RFC allows it.
But since we are using is_mail as the current mail validator, there is a filter that allows doing this:
So you can simply add something like this:
function no_periods_domain( $is_email, $email, $context ) {
if ( 'domain_no_periods' === $context ) {
return $email;
}
return $is_email;
}
add_filter( 'is_email', 'no_periods_domain', 10, 3 );
And you will be able to use those formats without trouble.
Return-Path: <supertester@example-test-2>
Received: from localhost (unknown [172.20.0.1])
by 144d19eeeff3 (Mailpit) with SMTP
for <admin@mailserver1>; Thu, 7 Aug 2025 10:34:17 +0000 (UTC)
Date: Thu, 7 Aug 2025 10:34:17 +0000
To: admin@mailserver1
From: WordPress <supertester@example-test-2>
Subject: Baseline test
Message-ID: <DcDMxyXzLdkJ4D6bdgNGeKaAa5TNkWcdChUNS4S4@localhost>
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)
x-my-things: thing3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
See attachments.
WP runs filters in both
is_email()andsanitize_email(). If necessary, you can run a filter on either of these so that if the$contextis 'email_too_short', you returntrueinstead.