Email Users 4.7.2 released

Late last week there was a request on the WordPress Support Forum to add a filter to allow control over the HTML which wraps email content (post/page notifications or email to users/groups).


This seemed like a reasonable request so I decided to look into it.  Adding a filter was fairly easy.  If the mailusers_html_wrapper filter exists, the default, and very basic, HTML wrapper is ignored and the filter is expected to properly construct the necessary HTML to wrap around email content.

This is the result of a email using the example filter now supplied as part of the plugin as viewed on my iPhone.

You can find the update in the WordPress plugin repository or an an update on your Dashboard.

* To customize the look of HTML email or to integrate with other
* plugins which enhance wp_mail() (e.g. WP Better Emails), use this
* hook to wrap the email content with whatever HTML is desired - or
* in some cases, none at all if another plugin will be adding the
* necessary HTML.
* This example wraps an "Urgent" message and table around the email
* content so the background can be styled. A table is the best way
* to do this because not all mail clients will recognize styling
* elements such as BODY and DIV like a traditional web page.
* Drop this code snippet and modify to suit your needs into your
* theme's functions.php file.
* @see
* @see
function mailusers_sample_html_wrapper($subject, $message, $footer)
// Wrap the HTML in proper header and body tags
// add some CSS styling to make the email look good.

$mailtext = sprintf('
table { border: 1px solid black; width: 800px; background-color: #c5f6c0; }
td { background-color: #c5f6c0 }
<table class="content">
<td class="content">
<div class="content">
<h1>This is an Urgent Message from Email Users!</h1>
<div class="footer">
</html>', $subject, $message, $footer) ;

return $mailtext ;

add_filter('mailusers_html_wrapper', 'mailusers_sample_html_wrapper', 10, 3) ;

9 thoughts on “Email Users 4.7.2 released

  1. Thumbs up! I’ll try it asap.

  2. Hello,

    I used the filter and a weird thing happens… the HTML from wp better emails doesn’t show up if I use the filter. Although it is applied at the same spot? I also played around with priority -1, 2, 999… no effect.
    Editing it direct still works.

    function mailusers_wp_better_emails_strip_html_wrapper($subject, $message, $footer) {
    // strip all whitespaces and comments and linebreaks (Important as wp better emails uses nl2br!)
    // also don't return any HTML as that is done by wp better emails
    $mailtext = preg_replace(array('/ {2,}/','/|\t|(?:\r?\n[ \t]*)+/s'),array(' ',''),$message);
    return $mailtext ;

    add_filter('mailusers_html_wrapper', 'mailusers_wp_better_emails_strip_html_wrapper', 10, 3) ;

    doesn’t work as tweaking the line manualy in email_users.php:

    $mailtext = preg_replace(array('/ {2,}/','/|\t|(?:\r?\n[ \t]*)+/s'),array(' ',''),$message);

    • If you turn on Debug, do you see the same result using the filter as you do when using the code modification you posted?

      I cannot see why the filter and the code change wouldn’t yield the same result at the same spot in the code.

      At the bottom of email-users.php is the filter I used to test it with. if you change the “if (0):” to “if (1):” does the filter get applied correctly?

  3. I’ll test it but just install wp better emails and see for yourself. If your too busy I’ll give you debug feedback asap.

  4. BTW your comments module stripped out code chunks so my regex isn’t 100% correct in the reply. But the regex is beside the point as I could also return the $message … for testing.

    • It took me the better part of two hours to figure out what WPBE is doing.

      Try adding this you your functions.php (or where ever you added the mailusers_html_wrapper filter) and let me know if it works. It works for me. If it works for you I’ll explain why.

      add_filter( 'wp_mail_content_type', 'mailusers_set_content_type' );
      function mailusers_set_content_type( $content_type ) {
      return 'text/plain';

  5. Pingback: | Email Users with WP Better Emails

  6. It kinda works, but add extra tags inbetween every paragraph what leads to pretty huge spaces in the mailings 🙁

  7. It seems like an autop problem

    I solved it by formatting the whole mail into 1 line with my own ” tags

Leave a Reply