boonebgorges / buddypress-group-email-subscription

Fine-grained email subscription for activity in BuddyPress groups
35 stars 31 forks source link

Mail Problem - Plain-Text instead of HTML with Buddypress 12.4.0 #249

Open christianlersch opened 4 months ago

christianlersch commented 4 months ago

Hi, I have another problem with the display of the notification emails. In Buddypress 12.2.0 everything works fine. See Screenshot. Then in Buddypress 12.3.0 the Problem starts to look like the second Screenshot. The Mail is not Formated in the Maintext as HTML and has also another text in it. I hoped that 12.4.0 would help, but it won't.

Do you have an idea for me what I can do? Did a Hook changed?

Maybe you can help. Thank you very much!

Cheers Chris

OK Buddypress 12-2-0 Broken Buddypress 12-4-0
boonebgorges commented 4 months ago

Sorry to hear you're having problems. I've tested between BP versions and I can't reproduce.

The "bracket" format in your screenshot looks like it was generated by the function ass_convert_links(). Prior to version 4.0.5 of BPGES, this function was used to strip HTML links out of content. It was removed as part of the work in #220. In current versions of BPGES, the function should never be run. This suggests to me that you may be running an older version of buddypress-group-email-subscription. Can you confirm? Or is there a chance you're running a customization that might force ass_convert_links() to run?

christianlersch commented 4 months ago

I not customize the ass_convert_links() :/

I also try more different things to fix it and I find a solution. If I do this in the file html2text.php

function convert_html_to_text($html) {
    // replace   with spaces
    return $html;

The mails looking good.

Is it possible to get a hook or anything that I could deactivate this function?

boonebgorges commented 4 months ago

The convert_html_to_text() function is used to generate the "plaintext" version of the email. This is the version used by clients that opt out of HTML email. Both versions, the HTML and plaintext, are sent with HTML emails, and the client decides which one to display. In your case, it appears that the plaintext version is being put into the HTML email body.

Are you running other plugins that modify the way that email is sent? Perhaps a plugin that forces WP emails to be formatted using HTML?

christianlersch commented 4 months ago

Yes, I use "Email Template Designer – WP HTML Mail", but I also try "Email Templates Customizer and Designer for WordPress and WooCommerce"... Both are not Working.

The only way is that I not use this Plugins and let your Plugin send the Mail over Buddypress. Than I get a HTML Mail.

But I need this Template Plugins, because all Mails from the Buddypress shout have the same design, and also need a Header Image and other Design parts. :-/

I not think that your Plugin is the Problem. I think something changed in the way Buddypress generate the Mail for sending. From the other plugins I have no chance to force that they will use the html content. :-/

Is there a Chance that I get a Hook or an option that your Plugin delievers HTML in any case? Or that I can change the ass_convert_links() function the way I do now?

Thanks for your help!

boonebgorges commented 4 months ago

Thanks for the clarification. BPGES is detecting that you're using the WP HTML Mail plugin, and is therefore falling back on wp_mail() rather than the BP email system. When this happens, BPGES assumes that your system doesn't know how to handle HTML in email content, so it converts it to plaintext.

There's no simple way to override this behavior. So I've introduced a new filter, which will be in the next version. See ba36aca. To use it, you can put something like the following in your own plugin/theme:

add_filter(
  'bpges_wp_mail_content',
  function( $plaintext_content, $original_content ) {
    return $original_content;
  },
  10,
  2
);

If you don't want to wait for the next BPGES release, you can try patching your installation with ba36aca.

christianlersch commented 4 months ago

Thank you very much that you want to help me!

I try your Patch in bp-activity-subscription-functions.php and also include the "add_filter" in the functions.php and this did not work. :-/

Then I try my patch in the html2text.php file and it not worked also. So I remove the patch in bp-activity-subscription-functions.php and my code in html2text.php work... I don't know if this informatin helps you...