• Resolved Max Ziebell

    (@max-ziebell)


    I am using WP Better Emails. It provides a HTML-wrapper (with Text fallback) to all emails sent throught wp_mail. Great thing!

    Now Email Users is also great but the HTML mode adds it own wrapper … may be good in most cases but in this case I only want the HTML of the message to be piped to wp_mail without Email Users doing anything to it.

    Basically I need to disable the HTML wrapper in HTML-Mode. Is there a hook I can do this with or are you gone provide a “no HTML wrapper” option?

    Please advise!

    https://www.ads-software.com/plugins/email-users/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Max Ziebell

    (@max-ziebell)

    Okay I hacked myself a solution but this will need to be reapplied every time Email Users is updated. Basically I changed email-users.php and changed this:

    if ('html' == $type) {
            if (mailusers_get_add_mime_version_header() == 'true')
    		    $headers[] = 'MIME-Version: 1.0';
    		$headers[] = sprintf('Content-Type: %s; charset="%s"', get_bloginfo('html_type'), get_bloginfo('charset')) ;
    		$mailtext = "<html><head><title>" . $subject . "</title></head><body>" . $message . $footer . "</body></html>";
    	} else {
            if (mailusers_get_add_mime_version_header() == 'true')
    		    $headers[] = 'MIME-Version: 1.0';
    		$headers[] = sprintf('Content-Type: text/plain; charset="%s"', get_bloginfo('charset')) ;
    		$message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
    		$message = preg_replace('|&|', '&', $message);
    		$mailtext = wordwrap(strip_tags($message . "\n" . $footer), 80, "\n");
    	}

    to this …

    if ('html' == $type) {
    		if (mailusers_get_add_mime_version_header() == 'true')
    		    $headers[] = 'MIME-Version: 1.0';
    		$mailtext = $message;
    	} else {
            if (mailusers_get_add_mime_version_header() == 'true')
    		    $headers[] = 'MIME-Version: 1.0';
    		$headers[] = sprintf('Content-Type: text/plain; charset="%s"', get_bloginfo('charset')) ;
    		$message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
    		$message = preg_replace('|&|', '&', $message);
    		$mailtext = wordwrap(strip_tags($message . "\n" . $footer), 80, "\n");
    	}

    And now it works.

    An option to omit the HTML-Body-Wrapper would be better!

    Thread Starter Max Ziebell

    (@max-ziebell)

    One quick correction: you have to make sure that wp better mail doesn’t get any newlines as it uses nl2br messing up HTML. So I stripped them (along with comments etc.):

    if ('html' == $type) {
           	if (mailusers_get_add_mime_version_header() == 'true')
    		    $headers[] = 'MIME-Version: 1.0';
    		$mailtext = preg_replace(array('/ {2,}/','/<!--.*?-->|\t|(?:\r?\n[ \t]*)+/s'),array(' ',''),$message);
    	} else {
            if (mailusers_get_add_mime_version_header() == 'true')
    		    $headers[] = 'MIME-Version: 1.0';
    		$headers[] = sprintf('Content-Type: text/plain; charset="%s"', get_bloginfo('charset')) ;
    		$message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
    		$message = preg_replace('|&|', '&', $message);
    		$mailtext = wordwrap(strip_tags($message . "\n" . $footer), 80, "\n");
    	}
    Plugin Author Mike Walsh

    (@mpwalsh8)

    I will look at adding a hook or filter to allow you to do something like you are proposing.

    It may be the sort of thing where the plugin has a default filter which you would need to remove in order to use your own HTML wrapper. That is my initial thinking on it as I sit here are Newark airport this morning waiting to go home. It will likely be a few days, maybe a week before I can look at this as I have a lot on my plate at work.

    Thread Starter Max Ziebell

    (@max-ziebell)

    Thumbs up. Looking forward to a maintainable solution! Thanks.

    Plugin Author Mike Walsh

    (@mpwalsh8)

    I have added the mailusers_html_wrapper filter and released 4.7.2. You can read more details and see an example of using the new filter on my web site.

    Thank you so much Max Ziebell.

    Although I got the newest version of Email Users I used the dirty trick of Max.

    I already got my template with wp better emails and all I wanted was Email users to insert the plain text into the template.

    Plugin Author Mike Walsh

    (@mpwalsh8)

    Max’s solution breaks when Email Users is updated which I expect to do shortly as I have fixed another bug in the activation code when a site has a large number of users.

    I have written up a post which explains the proper way to have WPBE and Email Users work together. The solution was posted in the comments on my blog last week.

    Plugin Author Mike Walsh

    (@mpwalsh8)

    There is an example (examples/wpbe.php) on how to setup the filters for WPBE and Email Users to work together in the 4.7.3 update which I pushed out today.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Email Users with WP Better Emails’ is closed to new replies.