I have a plugin which has its own register facility. This is on a multisite. I am using a must use plugin to send a custom activation email. This is the activation email which the user has to click in order to activate their account.
I am using the wpmu_signup_user_notification_email hook to catch the email and change the content. This is working, but the email is not html - any html such as header tags and paragraphs and br's are just included in the text.
How can I make this send a html based email.
Thank you
function my_signup_user_notification_email($content, $user_login, $user_email, $key, $meta)
{
$m = "<h1>Thanks for signing up</h1>";
$m .= $content;
return $m;
}
add_filter('wpmu_signup_user_notification_email', 'my_signup_user_notification_email', 10, 5);
I have a plugin which has its own register facility. This is on a multisite. I am using a must use plugin to send a custom activation email. This is the activation email which the user has to click in order to activate their account.
I am using the wpmu_signup_user_notification_email hook to catch the email and change the content. This is working, but the email is not html - any html such as header tags and paragraphs and br's are just included in the text.
How can I make this send a html based email.
Thank you
function my_signup_user_notification_email($content, $user_login, $user_email, $key, $meta)
{
$m = "<h1>Thanks for signing up</h1>";
$m .= $content;
return $m;
}
add_filter('wpmu_signup_user_notification_email', 'my_signup_user_notification_email', 10, 5);
Share
Improve this question
asked Mar 13, 2020 at 13:05
StripyTigerStripyTiger
2771 silver badge6 bronze badges
1 Answer
Reset to default 1Per the filter's documentation, the $content
should be formatted for use by wp_mail()
. In the wp_mail()
documentation, I find this:
The default charset is based on the charset used on the blog. The charset can be set using the
wp_mail_charset
filter.
So it appears you need to explicitly allow WordPress to send HTML mail. See the User Contributed Notes section of the wp_mail_charset
filter documentation.
Here's how I'd tackle your question:
/**
* Filter the mail content type.
*/
function wpse360648_set_html_mail_content_type() {
return 'text/html';
}
add_filter( 'wp_mail_content_type', 'wpse360648_set_html_mail_content_type' );
function wpse360648_user_notification_email( $content, $user_login, $user_email, $key, $meta ) {
$m = "<h1>Thanks for signing up</h1>";
$m .= $content;
return $m;
}
add_filter('wpmu_signup_user_notification_email', 'wpse360648_user_notification_email', 10, 5);
// Reset content-type to avoid conflicts -- https://core.trac.wordpress/ticket/23578
remove_filter( 'wp_mail_content_type', 'wpse360648_set_html_mail_content_type' );
(based on code by Helen Hou-Sandi)