WordPress new user email formatting issues

I have a WordPress site where i have Issue with the email, that user receives after creating an account.

Email that a user receives, looks like this: https://tinyurl.com/y45bgy5z

There is no formatting, no paragraph or no line breaks etc in the email. I have tried fixing this by adding filter for wp_new_user_notification_email but it did not worked: I have tried fixing it by using following:

add_filter('wp_new_user_notification_email', 'tpkcs_welcome_email', 10, 3);
function tpkcs_welcome_email($wp_new_user_notification_email, $user, $blogname)
   {
      $wp_new_user_notification_email['headers'] = 'Content-Type: text/html; charset=UTF-8';
      return $wp_new_user_notification_email;
   }

I have also tried this:

// Add content Type to emial template
function kcss_set_content_type(){
     return text/html;
}
add_filter( 'wp_mail_content_type','kcss_set_content_type' );

But none of the filters/actions worked either.

Topic html-email email Wordpress

Category Web


I had the same issue. I finally succeed to display the message with proper line breaks by surrounding the body of the message $wp_new_user_notification_email['message'],in your case, with html tags (html, head, body) and filtering it with nl2br.

Hope it will help.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.