Disabling HTML E-mail Templates for just one e-mail

“I have a question on HTML templates. Right now we are using it on http://www.mydomain.com

We are also using gravity forms. We need one form notification to sent in text and not using the HTML template because it sends the data to a CRM system that can not handle the HTML. Is it possible to bypass the HTML template for a certain email notification?”

So basically, is it possible to make some selected e-mails NOT to use HTML Email Templates? That should, I think, be forwarded to the developer :slight_smile:

  • Dimitris
    • Support Star

    Hey there Kregg,

    hope you’re doing good today! :slight_smile:

    There’s a filter in WP core that’s used to control mail content type.

    Have a look at last example here

    https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_content_type#Examples

    on how to set a ‘text/plain‘ type based on your conditions.

    Please keep in mind the priority value of wp_mail_content_type() filter, it should be 12 or higher, as HTML Email Templates plugin changes that to ‘text/html‘ using a priority of 11. :wink:

    Ref: wp-content/plugins/htmlemail/htmlemail.php#L155

    add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ), 11 );

    Hope that was some help!

    Warm regards,

    Dimitris

  • Kregg
    • WPMU DEV Initiate

    Yes, I know that filter, but the filter I have to apply is the one for the WPMU plugin, I cannot have a filter within a filter.

    I can use that to create something custom within GF but then, when it sends the email, it will be taken by WPMU’s plugin (which is based on the wp_mail() function).

    I think I should rather find a way to say, if the notification is from GF and not from WP Core then:

    add_filter( 'wp_mail_content_type', 'my_mail_content_type' , 11);
    function my_mail_content_type( $content_type ) {

    if ( $gravityformnotification ) {
    return 'text/plain';
    } else {
    //Apply WPMU's template
    }
    }

    I don’t think I can override WPMU’s html email by using the gform_pre_send_email function.

    Thanks.

  • Adam Czajczyk
    • Support Gorilla

    Hello Kregg!

    I have just asked one of our developers about this. I hope he could help us, though I’m not yet sure whether it’s more a matter of our plugin or rather Gravity Forms available hooks/filters. I’m awaiting developers response so please keep an eye on this thread and I’ll update it as soon as I get a reply.

    Best regards,

    Adam

  • Dimitris
    • Support Star

    Hey there Kregg,

    hope you’re doing good today and please excuse our late reply here, it seems that this issue slipped over our devs.

    I made some research and I can see that there’s already a filter in Gravity Forms plugin that controls the notifications’ email content type.

    Could you please add a new MU plugin file in your server like

    /wp-content/mu-plugins/change-gf-email-content-type.php

    (simply create the /mu-plugins/ folder if it doesn’t exist already)

    and add the exact following snippet in there:

    <?php
    add_filter( 'gform_notification', 'change_notification_format', 10, 3 );
    function change_notification_format( $notification, $form, $entry ) {

    // change notification format to text from the default html
    $notification['message_format'] = 'text';

    return $notification;
    }

    Reference: https://www.gravityhelp.com/documentation/article/gform_notification/#4-change-the-message-format

    Let us know how that goes!

    Warm regards,

    Dimitris

  • Kregg
    • WPMU DEV Initiate

    Hi Dimitris, thanks for your answer.

    We have that filter already set, the problem is not on GF but on WPMU’s HTML Email plugin. We have GF setup to send as text but once the notification goes out, WPMU’s plugin takes it and applies the html code (template) to it. I can tell you this because the template being applied is not the one we have set on GF but the one on HTML Email Template plugin.

    Is there any hook on your plugin to prevent to override Gravity Forms notifications?

    Thanks.

  • Adam Czajczyk
    • Support Gorilla

    Hello Kregg,

    It seems that the HTML Email plugin does its “magic” with a function hooked to a “wp_mail” WP filter hook (https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail).

    The callback function for that hook is processing the message content and adding a template to it then returning it to WP. That makes it a bit tricky because if you hooked up to “wp_mail” using lower priority than the plugin is using (it’s using default 10 so you’d use 9), you would be able to detect whether this is the specific message (e.g. by subject or message content) and do “something” with it, but then it would be processed by plugin anyway and templates would be applied.

    If you hooked with a higher priority (e.g. 11), that might work but the case would be:

    – you’d have a “message” already processed by plugin so it would be HTML message, using the HTML Email Templates template;

    – you’d need to find a way to either “clean it up” from the template HTML (or HTML entirely) or to bring back original message (maybe read from GF directly with some other hook eariler?).

    That being said, if you want to send that message in a plain text, maybe something like this would work:

    add_filter('wp_mail', 'gf_force_no_html_template', 11);
    function gf_force_no_html_template( $args ) {

    // this is the part to work out, to check if it's a specific message
    // e.g. by checking the subject line
    if ( $args['subject'] == 'THIS IS THE SPECIFIC SUBJECT LINE' ) {

    // remove all the HTML from message so it would be "plain text"
    $args['message'] = wp_strip_all_tags( $args['subject'] );

    }

    return $args;

    }

    Note please that the code above is not “ready to use” code, so you will want to review it and at least take care of the “if….” line there. Let me know if that helped at least a bit, please.

    Best regards,

    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.