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).

email_users_html_wrapper

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 https://wordpress.org/plugins/wp-better-emails/
* @see https://litmus.com/blog/background-colors-html-email
*
*/
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('
<html>
<head>
<title>%s</title>
<style>
table { border: 1px solid black; width: 800px; background-color: #c5f6c0; }
td { background-color: #c5f6c0 }
</style>
</head>
<body>
<table class="content">
<tr>
<td class="content">
<div class="content">
<h1>This is an Urgent Message from Email Users!</h1>
%s
</div>
<div class="footer">
%s
</div>
</td>
</tr>
</table>
</body>
</html>', $subject, $message, $footer) ;

return $mailtext ;
}

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