WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] emails have no line breaks. how to add them (23 posts)

  1. Ripplestone
    Member
    Posted 2 years ago #

    I was using Subscribe2. After an update, the E-mails started getting sent out with no line breaks. Meaning a well formatted blog post was being jumbled up into all 1 line with no spaces between paragraphs.

    To fix this I edited the subscribe2.php code.

    The origonal piece of code looked like this:

    // remove excess white space from with $excerpt and $plaintext
    		$excerpt = preg_replace('|\s+|', ' ', $excerpt);
    		$plaintext = preg_replace('|\s+|', ' ', $plaintext);
    		// prepare mail body texts
    		$excerpt_body = str_replace("{POST}", $excerpt, $mailtext);
    		$full_body = str_replace("{POST}", strip_tags($plaintext), $mailtext);
    		$html_body = str_replace("\r\n", "<br />\r\n", $mailtext);
    		$html_body = str_replace("{POST}", $content, $html_body);
    		$html_excerpt_body = str_replace("\r\n", "<br />\r\n", $mailtext);
    		$html_excerpt_body = str_replace("{POST}", $html_excerpt, $html_excerpt_body);

    I changed it to this:

    // remove excess white space from with $excerpt and $plaintext
    		// $excerpt = preg_replace('|\s+|', ' ', $excerpt);
    		// $plaintext = preg_replace('|\s+|', ' ', $plaintext);
    		// prepare mail body texts
    		$excerpt_body = str_replace("{POST}", $excerpt, $mailtext);
    		$full_body = str_replace("{POST}", strip_tags($plaintext), $mailtext);
    		$html_body = nl2br($mailtext);
    		$html_body = str_replace("{POST}", $content, $html_body);
    		$html_excerpt_body = nl2br($mailtext);
    		$html_excerpt_body = str_replace("{POST}", $html_excerpt, $html_excerpt_body);

    Hope that helps anyone who has the same problem. I spent hours looking for people talking about this, and ended up just editing the code myself.

    http://wordpress.org/extend/plugins/subscribe2/

  2. mattyrob
    Member
    Posted 2 years ago #

    @Ripplestone,

    Someone has reported this on here but I also cannot find it now :(

    Anyway, one fix is to comment out the lines. In the next version the lines will read:
    `$excerpt = preg_replace('|[ ]+|', ' ', $excerpt);
    $plaintext = preg_replace('|[ ]+|', ' ', $plaintext);'

    That should work to strip the excess white space without ruining layout. Weirdly it doesn't do this for all users!?!

  3. mattyrob
    Member
    Posted 2 years ago #

  4. Ripplestone
    Member
    Posted 2 years ago #

    Commenting out that codes works for "Single Posts".
    Note i also changed:

    $html_body = str_replace("\r\n", "<br />\r\n", $mailtext);

    with

    $html_body = nl2br($mailtext);

    But it doesn't completely fix the weekly Digest. I just got my weekly digest today (from working on this a week ago), and it's bunched together. Same as it is reported by @belg4mit in the ilnk you sent me.

    Sounds like I should just wait for the update in the next version.

    Thank you for your attention on this.

  5. mattyrob
    Member
    Posted 2 years ago #

    @Ripplestone,

    There are 2 preg_replace lines in the subsribe2_cron function that creates the digest email just like those in the single post code. Change those latter instances too and you should see a difference.

  6. Ripplestone
    Member
    Posted 2 years ago #

    Ok. I removed those 2 lines in the subscribe2_cron function.

    Now I'll wait a week to see if it sends out correctly.

    Thank you again for your support! I made a donation to the subscribe2 donation page. Hope you continue developing the subscribe2 further.

  7. Ripplestone
    Member
    Posted 2 years ago #

    I just notices there is a "Resend Digest" button in the Subscribe2 settings. I pressed that, and it sent an E-mail that looked correct! so It works now! :-)

  8. jeanjeana
    Member
    Posted 2 years ago #

    I'm still struggling with this issue, though I tried all the fixes mentioned here and on the other thread. I use Gmail and Thunderbird.

    I also tried a workaround where I put in the template where I wanted newlines, and replaced every mention of strip_tags($somestring) with strip_tags($somestring, '<p><a>'). The messages are now readable but unfortunately, I still lose all my links.

    Could the have anything to do with the headers? Notice that back when messages were working under 7.0.1, headers used have

    Content-Type: text/plain;

    Now the headers are

    Content-Type: text/html;

    Since I just want to send text excerpts, I tried commenting out references to the html content-type but it didn't work. Just thrashing around right now but I guess my subscribers can live without clickable links for a while.

    //if ( $type == 'html' ) {
    // To send HTML mail, the Content-Type header must be set
    //	$header['Content-Type'] = get_option('html_type') . "; charset=\"". get_option('blog_charset') . "\"";
    //		} else {
    $header['Content-Type'] = "text/plain; charset=\"".get_option('blog_charset') . "\"";
    //		}</a>
  9. mattyrob
    Member
    Posted 2 years ago #

    @jeanjeana,

    If your emails are coming as text/html either you have opted to get HTML notifications in Subscribe2->Your Subscriptions or you have bought Subscribe2 HTML.

    If it's the former visits Subscribe2->Your Subscriptions and change back to plain text notifications.

    If it's the latter, revert to the original code and post for help on the WPPlugins.com forum.

  10. jeanjeana
    Member
    Posted 2 years ago #

    Thanks--

    I only have the regular version of Subscribe2. I clearly checked off plain text excerpts at the bottom of settings, and the first thing I did was try different options to see if that would fix it. Is there another setting that I'm missing?

    After the adjustments I made, the email looks okay (including urls) as long as I configure my mail program to view it as plain text. However my subscribers will probably not know how to do this.

  11. mattyrob
    Member
    Posted 2 years ago #

    @jeanjeana,

    I clearly checked off plain text excerpts at the bottom of settings

    But that secretion is what happens to new users who register with your site if it's in the AutoSubscribe section.

    As I said above, your personal setting is at Subscribe2->Your Subscriptions.

  12. jeanjeana
    Member
    Posted 2 years ago #

    Hmm, I can't see any option to set personal settings to HTML or otherwise in Subscribe2->Your Subscriptions. I see only:

    Receive periodic summaries of new posts?: Yes No
    Do not send notifications for post made by these authors:

    ??

  13. mattyrob
    Member
    Posted 2 years ago #

    @jeanjeana,

    It seems as though you are sending emails on a periodic basis in a digest format them.

    I have no idea how you've managed to get the code sending in HTML format for this type of email. I'd suggest you revert to the original code and then apply this fix:

    Replace 4 instances of:
    preg_replace('|\s+|'
    With:
    preg_replace('|[ ]+|'

  14. Mrmark
    Member
    Posted 2 years ago #

    Yep @MattyRob - that last fix took care of it on my weekly digests.

  15. jeanjeana
    Member
    Posted 2 years ago #

    @MattyRob,

    Thank you for your reponse.

    I uninstalled and reinstalled 7.2 and made the replacements you suggested. It didn't work (and I tried it twice), so I am going to roll back to 7.0.1, which did work for me. I am using WP 3.2.1 and Arthemia, by the way. The problems I have been having since the reinstall are identical to the problems I had before the reinstall.

    I'll post back the results of rolling back.

  16. bartuniek
    Member
    Posted 1 year ago #

    I am having the same issue. I discovered that the
    <pre> tag disapeared from the emails. The emails that show newlines correctly have <pre> tag:

    <div id="messagebody"><div class="message-part">
    <pre>Blog ...</pre>

    Recently, all emails look like this:

    <div id="messagebody"><div class="message-htmlpart">
    <!-- html ignored --><!-- head ignored -->
    <!-- meta ignored --><div class="rcmBody"><p>Blog ...

    Don't know why it changed suddenly. Upgrading to the latest didn't help either.

  17. mattyrob
    Member
    Posted 1 year ago #

    @bartuniek,

    Subscribe2 doesn't strip HTML tags and replaced them with ignored tags like this. Are you sure you are in the right forum?

  18. bartuniek
    Member
    Posted 1 year ago #

    @mattyrob,

    I do not understand your post, so I will try to explain what I was trying to say.

    What I am saying is, that Subscribe2 used to send email notifications with an excerpt from a post that looked correctly in the email client, meaning that all the NewLine characters were correctly interpreted by the email client (I use Outlook for Desktop and RoundCube for Web). Recently, all emails that arrive in my inbox (Outlook and RoundCube) look like one blob of text without any line breaks. Looking inside the emails' source, I noticed that the underlying HTML has changed as described in my previous post. Upon further investigation, looks like all the emails are sent as HTML

    Content-Type: text/HTML; charset="UTF-8"

    used to be

    Content-Type: text/plain; charset="UTF-8"

    I've tried changing settings to force Plain Text for new subscribers, I tried forcing Plain Text for registered WordPress users using Mass Update, nothing works. Next, I'll try uninstalling Subscribe2 and re-installing it.

  19. mattyrob
    Member
    Posted 1 year ago #

    @bartuniek,

    What I'm trying to say, apparently quite poorly, is that the content of the email you pasted above does not look like something Subscribe2 would be doing. It seems the html pre tags have been replaced with the html ignored tags. Subscribe2 does not do that.

    Also, Subscribe2 sends text/plain by default to Public Subscribers, Registered Subscribers can choose their email type.

    DO NOT uninstall or you will lose all of the Subscribe2 plugin settings and subscriber details.

  20. bartuniek
    Member
    Posted 1 year ago #

    Uninstalling and re-instaling Subscribe2 didn't work. So we decided to re-install everything from scratch.

    We have made a new instance of WordPress and installed Subscribe2 and everything WORKS!!! I get Plain Text emails that correctly show line breaks in email excerpts. Examining the email source, we see

    Content-Type: text/plain; charset="UTF-8"

    So the question is, how can we get the old instance to go back to sending just plain text emails? Is there anything we should cleanup manually, since uninstalling didn't help?

  21. mattyrob
    Member
    Posted 1 year ago #

    @bartuniek,

    On the clean install were you using the same theme and all of the same plugins as the affected site? If not, install these individually and see if there is a conflict somewhere.

  22. bartuniek
    Member
    Posted 1 year ago #

    On the clean install we used different theme and just the Subscribe2 plugin.

    The problem is that no matter what, all emails go out as HTML. We noticed that also applies to WP password reminders. They arrive as "ContentType = 'text/HTML';" whereas before it was plain text.

    So we tried a hack to see what happens and changed the following in the PHPmailer to always send emails as 'text/plain':

    //Hack, force text/plain for all emails
    public function IsHTML($ishtml = true) {
        if ($ishtml) {
          $this->ContentType = 'text/plain';
        } else {
          $this->ContentType = 'text/plain';
        }
      }

    This hack kinda solved the problem and text emails from Subscribe2 and WP password reminders now arrive as text and are correctly displayed with line breaks. But the problem is still puzzling, why are all emails sent as HTML by PHPmailer?

    Any ides?

  23. mattyrob
    Member
    Posted 1 year ago #

    @bartuniek,

    That is probably a conflict coming from your theme or another plugin. I have seen instances of themes and plugins forcing content type to HTML. Not sure why the authors feel the need to apply a global filter to accomplish this for their own ends.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags