admin管理员组文章数量:1122826
I have allowed user registration on my wordpress site. I am using Buddypress and also added the User Registration plugin by WPEverest. Both allows users to register and sends them an activation email when they sign up.
I have noticed that for both of them, the email uses the username in the "to" field (and User Registration also uses the username in the email body but Buddypress uses the first name in the email body like "Hello First Name"). Because both forms end up having the username in the email's "to" field, I believe this is a wordpress thing and not plugin specific.
I would like the email to use the user's first name in the "to" field. Is there a way to force the activation emails to use the first name instead of the username in the "to" field, as well as the email body?
Thank you.
I have allowed user registration on my wordpress site. I am using Buddypress and also added the User Registration plugin by WPEverest. Both allows users to register and sends them an activation email when they sign up.
I have noticed that for both of them, the email uses the username in the "to" field (and User Registration also uses the username in the email body but Buddypress uses the first name in the email body like "Hello First Name"). Because both forms end up having the username in the email's "to" field, I believe this is a wordpress thing and not plugin specific.
I would like the email to use the user's first name in the "to" field. Is there a way to force the activation emails to use the first name instead of the username in the "to" field, as well as the email body?
Thank you.
Share Improve this question asked May 29, 2024 at 12:29 I have many questionsI have many questions 1717 bronze badges 4 |1 Answer
Reset to default 0Add the following code to your theme’s functions.php file if the plugin provides a filter for modifying email headers:
function custom_user_registration_email_to_field( $email ) {
$user_id = $email->get_user_id();
$user = get_userdata( $user_id );
if ( ! empty( $user->first_name ) ) {
$email->set_to( $user->first_name . ' <' . $user->user_email . '>' );
}
return $email;
}
add_filter( 'user_registration_email', 'custom_user_registration_email_to_field' );
本文标签: How to make registration activation email quottoquot field use registrant39s first name
版权声明:本文标题:How to make registration activation email "to" field use registrant's first name 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305560a1932633.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_mail()
is the email address. There is no other "to" field that I'm aware of, so either the way you've explained what you're referring to isn't right or this is specific to the plugins you've mentioned. – butlerblog Commented May 29, 2024 at 13:27wp_mail
][1] function allows you to filter the attributes that are send to it, including the 'to' field. However, unless you store the first name in a global variable, you cannot access that information in the filter, because it is not passed to the mail function. This means you will have to change it beforewp_mail
is called. Native WordPress has over a dozen functions doing this. Most likely your plugins do as well. [1]: developer.wordpress.org/reference/functions/wp_mail – cjbj Commented May 29, 2024 at 13:32