New user notification doesn't include activation link

admin2025-06-06  11

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: .php

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

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

And seeing this for the new user notification email:

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

To set your password, visit the following address:

<.php?action=rp&key=1nTPsJVMk3H2eEM3Wgpm&login=test19>

.php
"
  ["headers"]=>
  string(0) ""
  ["attachments"]=>
  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'.

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/wp-login.php

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

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

And seeing this for the new user notification email:

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

To set your password, visit the following address:

<http://www.domain/wp-login.php?action=rp&key=1nTPsJVMk3H2eEM3Wgpm&login=test19>

http://www.domain/wp-login.php
"
  ["headers"]=>
  string(0) ""
  ["attachments"]=>
  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'.

Share Improve this question asked Nov 17, 2018 at 20:51 Louis WLouis W 4741 gold badge6 silver badges18 bronze badges 6
  • 1 The code you see in the var_dump is correct, see the documentation developer.wordpress/reference/functions/… line 1899. The problem lies somewhere else. Any chance it could be email client side? – Clinton Commented 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 Commented 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 Commented Nov 17, 2018 at 23:21
  • @butlerblog How is the format of the link correct? Is it not supposed to be HTML? – Louis W Commented 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 Commented Nov 18, 2018 at 12:50
 |  Show 1 more comment

1 Answer 1

Reset to default 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749172356a316970.html

最新回复(0)