Make WordPress Core

Opened 7 years ago

Closed 14 months ago

Last modified 10 months ago

#48951 closed feature request (worksforme)

email_too_short is not good email validation candidate

Reported by: dingo_d Owned by:
Priority: low Milestone:
Component: Mail Version: 5.4
Severity: trivial Keywords: 2nd-opinion
Cc: Focuses:

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)

#1 @SergeyBiryukov
7 years ago

  • Component Formatting → Mail

#2 @cbutlerjr
6 years ago

  • Priority normal → low
  • Severity normal → trivial
  • Type defect (bug) → feature request

but WordPress doesn't so you don't have consistent behavior

WP runs filters in both is_email() and sanitize_email(). If necessary, you can run a filter on either of these so that if the $context is 'email_too_short', you return true instead.

#3 @SirLouen
14 months ago

  • Resolution → worksforme
  • Status new → 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:

​https://github.com/SirLouen/wordpress-develop/blob/f152321f2fe5665cb28486de04fa54bdf58fb252/src/wp-includes/formatting.php#L3604-L3608

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.

#4 @swissspidy
10 months ago

  • Milestone Awaiting Review

Removing milestone from closed ticket.

Note: See TracTickets for help on using tickets.