• Resolved honeybadger19

    (@honeybadger19)


    First of all, thank you for such a wonderful plugin and providing it to the community for free. Thank you for your generosity.

    Just a quick bug report which I hope will be helpful to you:

    With PMPRO plugin installed, emails that are sent by WP and other plugins lose all their line breaks and become a long string of text.

    Fyi, I have ticking/unticking the box in PMPRO email settings that says…

    “If unchecked, all emails from “WordPress <[email protected]>” will be filtered to use the above settings.”

    …makes no difference.

    Could the problem be because PMPRO did not reset ‘wp_mail_content_type’ back to ‘text/plain’ after it has sent messages?

    According to WP Codex:

    The default content type is ‘text/plain’ which does not allow using HTML. You can set the content type of the email either by using the ‘wp_mail_content_type’ filter (see example below), or by including a header like “Content-type: text/html”. Be careful to reset ‘wp_mail_content_type’ back to ‘text/plain’ after you send your message, though, because failing to do so could lead to unexpected problems with e-mails from WP or plugins/themes.

    URL:
    https://codex.www.ads-software.com/Function_Reference/wp_mail

    https://www.ads-software.com/plugins/paid-memberships-pro/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter honeybadger19

    (@honeybadger19)

    Version of PMPRO: 1.7.11

    I have exactly the same issue: Version of PMPRO: 1.7.11

    If the plugin is active, all other emails sent by WP loose their line breaks/html tags

    If I deactivate it, emails are sent in the right format

    Plugin Author Jason Coleman

    (@strangerstudios)

    Hi, guys. Looking into it.

    We’re looking into this, but in the meantime, most people can solve these types of issues by disabling the PMPro email content type filter with this code:

    remove_filter('wp_mail_content_type', 'pmpro_wp_mail_content_type');

    You’ll want to add that to your active theme’s functions.php file or customizations plugin.

    Hi,
    I just migrated to PMPRO and face this issue also. Do you guys have any update yet?

    cubryto, did you try the solution mentioned above your post?

    Thanks for the code, messica. This fixed the issue for me. I look forward to this issue being addressed in a future release.

    Great, marking this as resolved.

    I don’t think this should have been marked as resolved. I am having the very same issue. Your solution is not really a solution at all if you want to use a template (and HTML), which I suspect many folks want to do (including me).

    On the other hand, one solution is quite simple. Instead of reverting back to text, keep the HTML but modify the body of the email you send in the pmpro_send_html function (email.php file). Specifically, two things are needed. First, if we are dealing with a text-only message (like the WP system emails), we need to convert newlines to <br />. Easy. Before the following line:

    // Get header for message if found

    Add this line:

    if ($original_body == strip_tags($original_body)) $phpmailer->Body = nl2br($phpmailer->Body);

    The second thing needed actually solves a different problem that exists but wasn’t noted, namely that HTML messages are not being converted to plain text for the multi-part email as we would expect. Again, the fix is easy. We need to modify $phpmailer->AltBody in two ways: (1) convert HTML <br> instances to newlines and (2) strip HTML tags.

    Simply replace the following line:

    $phpmailer->AltBody = wp_specialchars_decode($phpmailer->Body, ENT_QUOTES);

    with these lines:

    $phpmailer->AltBody = preg_replace('#<br\s*/?>#i', "\n", $phpmailer->Body);
    $phpmailer->AltBody = wp_specialchars_decode(strip_tags($phpmailer->AltBody), ENT_QUOTES);

    Obviously, changing your email.php file is not smart because it presumably will get overwritten with your next update. So, for now I have made a modified copy of your functions (renamed) and I am using remove_filter and add_filter to use these modified versions. I hope you will consider making these changes (I am sure they can probably be improved, this is just some quick work on my part).

    Jason rarely reads this forum and I’m guessing is unlikely to read a thread marked ‘resolved.’ I suggest you post to Stranger Studios on github. Much more likely for it to be seen there.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Bug: Non-PMPRO emails lose their line breaks and become a single long string’ is closed to new replies.