• Resolved wpturk

    (@wpturk)


    Hi Markus,
    I would like to send html emails with this plugin. Can you give me a hint? Is there an easy way?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Markus Echterhoff

    (@mechter)

    Hi @wpturk, try something like this (e.g. added to your theme’s functions.php):

    add_filter( 'bbp_subscription_email_headers', function( $headers ) {
    	array_push( $headers, 'MIME-Version: 1.0', 'Content-Type: text/html; charset=UTF-8' );
    	return $headers;
    } );
    
    add_filter( 'bbp_forum_subscription_email_message', function( $message, $forum_id, $topic_id ) {
    	$topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES );
    	$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
    	$topic_url = get_permalink( $topic_id );
    	$topic_content = wp_specialchars_decode( strip_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES );
    	
    	return sprintf( '<p>%s posted new topic <a href="%s">%s</a></p><p>%s</p>', $topic_author_display_name, $topic_url, $topic_title, $topic_content );
    } );		
    
    add_filter( 'bbp_topic_subscription_email_message', function( $message, $forum_id, $topic_id, $reply_id ) {
    	$reply_author_display_name = bbp_get_reply_author_display_name( $reply_id );
    	$reply_url = bbp_get_reply_url( $reply_id );
    	$reply_content = wp_specialchars_decode( strip_tags( bbp_get_reply_content( $reply_id ) ), ENT_QUOTES );
    	
    	return sprintf( '<p>%s replied:</p><p>%s</p><p><a href="%s">Read Online</a></p>', $reply_author_display_name, $reply_content, $reply_url );
    } );
    
    Thread Starter wpturk

    (@wpturk)

    Thank you Markus, this is great. I will test.

    Do you know any easy way to use an email template, so that your functions only push topic_title, topic_author_display_name, topic_url, topic_content etc. and all html/css stuff comes from the template.

    Plugin Author Markus Echterhoff

    (@mechter)

    Sure. In the above example code, the message filters return an html string. That string could also be loaded from a template by using php output buffers like so:

    ob_start();
    include( get_stylesheet_directory() . '/email_templates/new_topic_message.html' );
    $ob = ob_get_clean();
    

    Then you simply replace any tokens in the template with author name, content etc and return the result.

    Thread Starter wpturk

    (@wpturk)

    Hi Markus, I get somehow blank page after posting a reply. I used your above code in functions.php

    add_filter( 'bbp_subscription_email_headers', function( $headers ) {
    	array_push( $headers, 'MIME-Version: 1.0', 'Content-Type: text/html; charset=UTF-8' );
    	return $headers;
    } );
    
    add_filter( 'bbp_forum_subscription_email_message', function( $message, $forum_id, $topic_id ) {
    	$topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES );
    	$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
    	$topic_url = get_permalink( $topic_id );
    	$topic_content = wp_specialchars_decode( strip_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES );
    	
    	return sprintf( '<p>%s posted new topic <a href="%s">%s</a></p><p>%s</p>', $topic_author_display_name, $topic_url, $topic_title, $topic_content );
    } );		
    
    add_filter( 'bbp_topic_subscription_email_message', function( $message, $forum_id, $topic_id, $reply_id ) {
    	$reply_author_display_name = bbp_get_reply_author_display_name( $reply_id );
    	$reply_url = bbp_get_reply_url( $reply_id );
    	$reply_content = wp_specialchars_decode( strip_tags( bbp_get_reply_content( $reply_id ) ), ENT_QUOTES );
    	
    	return sprintf( '<p>%s replied:</p><p>%s</p><p><a href="%s">Read Online</a></p>', $reply_author_display_name, $reply_content, $reply_url );
    } ); 
    Plugin Author Markus Echterhoff

    (@mechter)

    Sorry about that. The code was untested. The number of filter arguments was missing and also I discovered that the MIME type was added a second time by WordPress, so I removed that part. Here is a tested version that works for me:

    add_filter( 'bbp_subscription_email_headers', function( $headers ) {
    	$headers []= 'Content-Type: text/html; charset=UTF-8';
    	return $headers;
    } );
    
    add_filter( 'bbp_forum_subscription_email_message', function( $message, $forum_id, $topic_id ) {
    	$topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES );
    	$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
    	$topic_url = get_permalink( $topic_id );
    	$topic_content = wp_specialchars_decode( strip_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES );
    
    	return sprintf( '<p>%s posted new topic <a href="%s">%s</a></p><p>%s</p>', $topic_author_display_name, $topic_url, $topic_title, $topic_content );
    }, 10, 3 );
    
    add_filter( 'bbp_topic_subscription_email_message', function( $message, $forum_id, $topic_id, $reply_id ) {
    	$reply_author_display_name = bbp_get_reply_author_display_name( $reply_id );
    	$reply_url = bbp_get_reply_url( $reply_id );
    	$reply_content = wp_specialchars_decode( strip_tags( bbp_get_reply_content( $reply_id ) ), ENT_QUOTES );
    
    	return sprintf( '<p>%s replied:</p><p>%s</p><p><a href="%s">Read Online</a></p>', $reply_author_display_name, $reply_content, $reply_url );
    }, 10, 4 );
    Plugin Author Markus Echterhoff

    (@mechter)

    *MIME version, not type.

    Thread Starter wpturk

    (@wpturk)

    Works like a charm! Thanks for your 5 star support!

    Plugin Author Markus Echterhoff

    (@mechter)

    Glad I could help. Thanks for your friendly review. ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘html emails’ is closed to new replies.