Make WordPress Core

Opened 5 years ago

Closed 13 months ago

Last modified 12 months ago

#54465 closed enhancement (invalid)

Error message with invalid receipent

Reported by: sanzeeb3 Owned by:
Priority: normal Milestone:
Component: Mail Version: 5.8
Severity: normal Keywords:
Cc: Focuses:

Description

When sending an email with:

wp_mail( 'nameSurname.@gmail.com', 'Subject', 'Message' );

we get the error message: "You must provide at least one recipient email address".

Though the recipient is invalid, it's provided.

Related to: https://core.trac.wordpress.org/ticket/47467 but it does not seem to be fixed.

Change History (2)

#1 @SirLouen
13 months ago

  • Resolutioninvalid
  • Status newclosed

According to the RFC 5322, section 3.4.1, emails starting and ending with a dot are not permitted (dot-atom format means, atext with dots surrounded with atext only, atext doesn't include dots (More info about types of tokens)

So basically, here is that this address nameSurname.@gmail.com is not valid.

If you check PHPMailer code basically its failing to spot a to, a cc or a bcc because its unable to find a valid address with an @ because of that dot,

Maybe you could find some help with this little workaround: I was able to bypass this by setting the wp_mail_from filter like this:

add_filter('wp_mail_from', function($original_email_address) {
     return 'wordpress@server.local'; 
});

Although using my example code for sending emails:

<?php
function send_email_menu() {
        add_menu_page(
                'Send Test Email',
                'TestEmail Sender',
                'manage_options',
                'send-email-page',
                'send_email_page_html'
        );
}
add_action( 'admin_menu', 'send_email_menu' );

function send_email_page_html() {
        ?>
        <div class="wrap">
                <h1>Send a Test Email</h1>
                <?php
                if ( isset( $_POST['send_email'] ) && 1 === (int) $_POST['send_email'] ) {
            $to = "nameSurname.@gmail.com";
            $subject = "Subject";
            $body = "Message";

                        if ( wp_mail( $to, $subject, $body) ) {
                                echo '<div class="notice notice-success is-dismissible"><p>Message successfully sent.</p></div>';
                        } else {
                                echo '<div class="notice notice-error is-dismissible"><p>Message sending failed.</p></div>';
                        }
                }
                ?>
                <form method="post" action="">
                        <input type="hidden" name="send_email" value="1">
                        <?php submit_button( 'Send Test Email' ); ?>
                </form>
        </div>
        <?php
}

We can see that this is the result when sending the email:

Return-Path: <wordpress@mailhog.local>
Received: from localhost (wordpress-develop-php-1.wordpress-develop_wpdevnet. [172.18.0.3])
        by d2756ddb9791 (Mailpit) with SMTP
        for <nameSurname.@gmail.com>; Sat, 12 Jul 2025 17:25:56 +0000 (UTC)
Date: Sat, 12 Jul 2025 17:25:56 +0000
To: nameSurname.@gmail.com
From: WordPress <wordpress@server.local>
Subject: Subject
Message-ID: <nUcLDNeY6tTDsDB3ReQB88Sfd3pQrxN0QRugoMqqR4@localhost>
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

Message

The email, although, is being delivered with wp_mail despite not being compliant. So I don't recommend you using an email like such

Closing this for being invalid for not compliant with the RFC.

Version 1, edited 13 months ago by SirLouen (previous) (next) (diff)

#2 @peterwilsoncc
12 months ago

  • Milestone Awaiting Review
Note: See TracTickets for help on using tickets.