Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shows how to wrap an outgoing Participants Database email with an HTML framework
* Plugin Name: PDb HTML Email Wrapper
* Description: Adds a structural HTML wrapper to outgoing Participants Database emails.
class pdb_email_html_wrapper {
public function __construct()
// this filter is called in PDb_Template_Email::send_email()
add_filter( 'pdb-template_email_html_body', array($this, 'wrap_email_body'), 20, 2 );
* wraps the email body of all Participants Database outgoing emails
* @param string $body the email body
* @param \PDb_Template_Email $template instance
* @return string the email body
public function wrap_email_body( $body, $template )
return str_replace( '{body}', $body, $this->wrapper() );
* provides the html wrapper
* this wrapper must contain the {body} placeholder where the unwrapped email body goes
* this wrapper is based on an article in
* @see
* @return string
private function wrapper()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html lang="en" xmlns="" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body style="margin:0;padding:0;min-width:100%;background-color:#ffffff;">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="min-width: 100%;" role="presentation">
return ob_get_clean();
// invoke the class
new pdb_email_html_wrapper;

This comment has been minimized.

Copy link
Owner Author

@xnau xnau commented Sep 5, 2020

This will wrap the body of all Participants Database emails in a recommended HTML framework.

This is really only necessary to address layout issues with inconsistent CSS implementation across email clients. It has no effect on deliverability.

If you want to be selective about which emails get this treatment, inspect the $template object in the filter handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment