When adding new users through the Dashboard, I've noticed that the notification email sent to a user when then have been added to Wordpress doesn't work correctly. Included in the email is the following line, however you'll notice that the registration key is missing and the link is not rendered properly.

To set your password, visit the following address: http://www.domain.com/wp-login.php

I did some digging around, outputting the contents of wp_mail like so:

    add_filter('wp_mail', function($email) {
        return $email;
    }, 1);

And seeing this for the new user notification email:

array(5) {
  string(20) "[email protected]"
  string(47) "[My Great Blog] Your username and password info"
  string(224) "Username: test19

To set your password, visit the following address:


  string(0) ""
  array(0) {

What's weird is that it sort of includes a correct link, but the HTML is malformed (no A href=""), and it's missing the closing . I have confirmed this on Wordpress Trac.

Anyone have any insight onto why this is not working, seems like such a crucial part of a website.

Version 4.9.8.

Already set 'wp_mail_content_type' to text/html'.

  • 1
    The code you see in the var_dump is correct, see the documentation developer.wordpress.org/reference/functions/… line 1899. The problem lies somewhere else. Any chance it could be email client side?
    – Clinton
    Nov 17, 2018 at 21:56
  • 1
    As already noted, the format of the link is correct in your var_dump. But I wanted to add why it's not "malformed" HTML - WP's emails are plain text. What you're looking at in the link is correct (unfortunately, that doesn't solve your issue, but it may help prevent you from chasing shadows).
    – butlerblog
    Nov 17, 2018 at 22:54
  • I added a comment to Clinton's answer below, but wanted to add it here as well to make sure you saw it. You really need to change the priority of the filter you're running to get your var_dump. You're running it at priority 1 (the earliest possible). So you know the link is OK here. But you need to see if something else is running a wp_mail filter at the default priority (10) or later, so I would say change the priority from 1 to 100 so you can see if the issue is another wp_mail filter somewhere.
    – butlerblog
    Nov 17, 2018 at 23:21
  • @butlerblog How is the format of the link correct? Is it not supposed to be HTML?
    – Louis W
    Nov 18, 2018 at 3:49
  • Because it's not an HTML email - it's plain text - WP's default does not send HTML email. Even if you change the format using the "wp_mail_content_type" filter, it's still generated as a plain text message. Looking at it as an HTML <a href> tag, it would look wrong - but that's not what it is. The message text in what you posted is what the expected result should be.
    – butlerblog
    Nov 18, 2018 at 12:50

1 Answer 1


WordPress 4.9.0 introduced 2 filters into the new user notification mail function (wp_new_user_notification):

  • wp_new_user_notification_email - to customise the email sent to User
  • wp_new_user_notification_email_admin - to customise the email email sent to Admin

We can ignore the second as this is the email sent to the admin the format is different from that in your question. wp_new_user_notification_email on the other hand allows you to modify the 'to', 'subject', 'message' and 'headers' before these are sent to the wp_mail() function.

However, you intercepted the wp_mail filter which fires immediately after wp_new_user_notification_email and everything looks fine at that point, so the issue must be later. The only remaining place that the message could be filtered is through the wp_mail filter.

If you are convinced that there is no issue with charset or client side email, then look for any other calls to add_filter('wp_mail', ...). Also check out the source code of the email received.

Sorry I can't be more help. This is an interesting question and I look forward to hearing finally what the solution is or any other suggestions.

  • 2
    @Louis V - since you're running a filter on wp_mail to get your var_dump and taking into consideration what Clinton said, you probably should change the priority on your wp_mail filter to a later priority so you can see if there are other filters being run on it. You've got it set at "1". Change that to "100" so you can see if something else is causing your issue on a wp_mail filter. If something else is filtering wp_mail, it's most likely going to be a default priority (10) or later, so your "1" is too early to get all the insight you need.
    – butlerblog
    Nov 17, 2018 at 22:58
  • Thanks for the reply. I'm testing this on a totally empty theme with no other customizations. Changing the priority (no idea why it was set to 1) produces no different outcome. Pay close attention fo the link html in my original post. Why is that not proper HTML?
    – Louis W
    Nov 18, 2018 at 3:45
  • 1
    Disappointing that changing the priority did not change the outcome. That's going to make it difficult to track down. (The reason the link is not proper HTML is that the message generated is a plain text email - not and HTML email. It's not supposed to be an <a href> tag.)
    – butlerblog
    Nov 18, 2018 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.