How to remove line breaks in e-mails sent by phpBB

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
User avatar
Marek Muc
Registered User
Posts: 90
Joined: Tue Sep 04, 2018 2:59 pm
Location: Warsaw, Poland
Contact:

How to remove line breaks in e-mails sent by phpBB

Post by Marek Muc »

E-mails sent by phpBB seem to have line breaks in them, which causes those e-mails look 'untidy' on narrow screens. For example this is how a topic reply notification looks like on my mobile phone:
topic reply email-.JPG
I would like to remove those line breaks, but when I open the relevant .txt file in \language\en\email I can't see any line breaks there (I'm using sublime text).

How to remove those line breaks?
Last edited by Mick on Fri Sep 11, 2020 1:12 pm, edited 1 time in total.
Reason: Moved from support.
User avatar
axe70
Registered User
Posts: 369
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by axe70 »

I did time ago a modification to send full html email with full post reply, editing files you mention above, and
/phpbb/notification/type/post.php
/phpbb/notification/type/topic.php

You can find the needed vars assigned to email template where:

Code: Select all

	'AUTHOR_NAME'				=> htmlspecialchars_decode($username),
			'POST_SUBJECT'				=> htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
			'TOPIC_TITLE'				=> htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
and i really do not know if there is an event listener about this somewhere (do not think), to clean up/check result, when never the problem come out from phpBB (strange) and not by the program sublime text, that again, i ignore.
But you can check so the output, printing it into a file maybe (i even do not remember how i did this time, if putting a print_r();exit; or as said, writing results to a file). Hope this will help someway, good luck and cheers!
User avatar
Marek Muc
Registered User
Posts: 90
Joined: Tue Sep 04, 2018 2:59 pm
Location: Warsaw, Poland
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by Marek Muc »

thanks... but I have no idea how your reply could help me in removing line breaks from those e-mails... I understand that I can edit the email files in \language\en\email but this has no effect on those line breaks. I also don't need to change or add variables... I just don't want these emails looking messy on mobile devices
User avatar
axe70
Registered User
Posts: 369
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by axe70 »

In effect will not help. Now i little remember that i had to point you into this instead:
/phpBB3/includes/functions_messenger.php
where there are listeners for all functions that send out emails.
But i assume it is not the way to resolve your problem, since you do not can or want put eyes on code.
Cheers!
User avatar
Marek Muc
Registered User
Posts: 90
Joined: Tue Sep 04, 2018 2:59 pm
Location: Warsaw, Poland
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by Marek Muc »

no problem for me to change code an upload a modified file, but I'm not able to figure out what needs to be changed
so you believe that the line breaks are added by /phpBB3/includes/functions_messenger.php? are you able to identify the exact location within the file?
User avatar
EA117
Registered User
Posts: 2143
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by EA117 »

No definitive idea as to the "why".

But the message is being first processed through a utf8_wordwrap() helper call, which defaults to 75 characters width. Which is the same default that PHP's wordwrap() would have. The output of the UTF-8 method is then passed to the normal PHP wordwrap() method, but with width specified as 997 characters and a hard split:

Code: Select all

wordwrap(utf8_wordwrap($msg), 997, "\n", true)
This is done for both the SMTP code path and the PHP mail() code path. For example, in lines 628, 951 & 1929 in the phpBB 3.3.1 version of /includes/functions_messenger.php.

Since ~990 appears to be the expected SMTP line length limit, presumably that's why the 997 override was specified to the PHP wordwrap(). But was it a mistake or was it intentional when the double-wordwrap was introduced was introduced that the UTF-8 compatible word wrap was not provided with the same line length override? Were the parameters we're seeing passed to the PHP wordwrap() meant to be specified to the utf8_wordwrap() instead? Not sure.

Maybe the "double-wordwrap" with different line length limits is intentional for a non-declared and non-commented reason. Or maybe it was an earlier proposed workaround to the utf8_wordwrap() issues, which was supposed to have been removed once the bugs in the utf8_wordwrap() method had been fixed.

But if I was trying to fix word wrapping in the message content, I would try replacing the double-wordwrap at all three of those locations with just a single utf8_wordwrap() call, using the parameters that were being passed to the PHP wordwrap() at those same locations:

Code: Select all

utf8_wordwrap($msg, 997, "\n", true)
User avatar
axe70
Registered User
Posts: 369
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by axe70 »

Marek Muc wrote:
Sun Sep 13, 2020 7:24 pm
no problem for me to change code an upload a modified file, but I'm not able to figure out what needs to be changed
so you believe that the line breaks are added by /phpBB3/includes/functions_messenger.php? are you able to identify the exact location within the file?
Should be, if using smtp:

Code: Select all

function smtpmail($addresses, $subject, $message, &$err_msg, $headers = false)
{
	global $config, $user;
so just after put print_r($message);exit;

or if with PHP's mail function

Code: Select all

function phpbb_mail($to, $subject, $msg, $headers, $eol, &$err_msg)
{
	global $config, $phpbb_root_path, $phpEx;

	// Convert Numeric Character References to UTF-8 chars (ie. Emojis)
	$subject = utf8_decode_ncr($subject);
	$msg = utf8_decode_ncr($msg);
so just after put print_r($msg);exit;

or you can check inside

Code: Select all

function send($method = NOTIFY_EMAIL, $break = false)
	{
where this line:
$message = trim($this->template->assign_display('body'));
so just after put: print_r($message);exit;

I do not which of those may will work for you, hope that this will may help

p.s note that with print_r() if there are white spaces, may you'll not see differences on output (may yes) if you do not look source using the browser's option View Page Source
As you may know you can also use var_dump($message);exit;
User avatar
Marek Muc
Registered User
Posts: 90
Joined: Tue Sep 04, 2018 2:59 pm
Location: Warsaw, Poland
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by Marek Muc »

that you for you replies! I didn't expect it to be so complicated! Honestly I kind of understand EA117's reply only, so I'll focus there :)
EA117 wrote:
Sun Sep 13, 2020 8:21 pm

But the message is being first processed through a utf8_wordwrap() helper call, which defaults to 75 characters width.
This seems to be the key, as the lines are indeed wrapped before (or when) they reach 75 characters. But after having read your post a few times I still don't get how to change it. I'm able to find the lines of code that you inserted, but they refer to 997 characters, which is long enough, so no need to edit that one. But I still don't get what should I try changing to avoid wrapping text after 75 characters, would you be so kind to reiterate it in a more noob-friendly way? :)

thank you in advance!

PS I submitted this as a bug:
https://tracker.phpbb.com/browse/PHPBB3-16601
User avatar
axe70
Registered User
Posts: 369
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by axe70 »

mhh ... May i'm wrong, but are you sure that it is? Because based on your screenshot, you have line breaks even before chars reach 75 in the line
May to check what will be mailed, check with this:

where:

Code: Select all

			// Parse message through template
		$message = trim($this->template->assign_display('body'));
	{
just after put:
echo $message;exit; or var_dump($message);
you should see the content of the email that will be sent out.

And may you'll have to cleanup this result, before to pass it into email. But it is strange: i had to do this when i did the work i mentioned before, sending out html emails with post content embedded.
But for what i know, phpBB emails are not html emails by default. Only plain text. Isn't it?
So or something still need to be cleaned out, like strings you pass into email which you may edited, and that contains unwanted chars causing the problem, or it seem to me strange.

I see anyway, based into your posted screenshot, that you edited the file with default values?
I would like to see how you edited these files. May there is something wrong on?

And finally surely it is not but: are you sure that it is not a problem, into other program you mention that presents email output into your device? Did you already tested it with another email not sent out by phpBB? I assume you're sure of this.

[EDITED]
Last edited by axe70 on Mon Sep 14, 2020 1:34 pm, edited 1 time in total.
User avatar
Marek Muc
Registered User
Posts: 90
Joined: Tue Sep 04, 2018 2:59 pm
Location: Warsaw, Poland
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by Marek Muc »

the line breaks so that a full word is not split into 2 parts, so the split may happen earlier than at 75 characters

I'm sure this is not my email client's fault, as the word wraps in emails sent by phpBB are visible in browsers as well. For other emails (not sent by phpBB) this problem does not exist - line break 'responsively' according to screen size

In doesn't matter whether these are standard phpBB emails or whether I modify them, line breaks are inserted in both instances.

PS. I'm sorry but I don't understand what I would achieve by

Code: Select all

echo $message;exit;
User avatar
axe70
Registered User
Posts: 369
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by axe70 »

You should see the body output of the email you'll go to receive and that will be sent out.
At this point, you can check the content of the email body you'll go to receive, so substantially, you'll see for example:
Subject: Topic reply notification - "Another test rotation" List-Unsubscribe: Hello admin, You are receiving this notification because you are watching the topic "Another test rotation" at "phpBB subdomain.w3host.com". This topic has received a reply by tester since your last visit. No more notifications will be sent until you visit the topic. If you want to view the newest post made since your last visit, click the following link: https://subdomain.w3host.com/phpbb3/vie ... ead#unread If you want to view the topic, click the following link: https://subdomain.w3host.com/phpbb3/vie ... p?f=2&t=25 If you want to view the forum, click the following link: https://subdomain.w3host.com/phpbb3/viewforum.php?f=2 If you no longer wish to watch this topic you can either click the "Unsubscribe topic" link found at the bottom of the topic above, or by clicking the following link: https://subdomain.w3host.com/phpbb3/vie ... atch=topic -- Thanks, The Management
Or messes, if there are. So you'll be sure about what will be passed into the email body. And start to know where/why your problem come out.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52627
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by Brf »

EA117 wrote:
Sun Sep 13, 2020 8:21 pm

Maybe the "double-wordwrap"
It looks to me that the line-wrap is happening at the template-tag, not any specific character count.
User avatar
Marek Muc
Registered User
Posts: 90
Joined: Tue Sep 04, 2018 2:59 pm
Location: Warsaw, Poland
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by Marek Muc »

@axe70 - I've seen this behaviour in emails sent from phpBB.com and my domain, but now I figured I'll see how it works with different email client. When I use Microsoft Outlook, these line breaks are not there, so it seems as if Gmail (both mobile Android app and browser version) 'sees' them, whereas Outlook does not (or sees them, but decides to ignore).
User avatar
axe70
Registered User
Posts: 369
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by axe70 »

I think you should be sure that the body do not contain characters causing the issue.
May a cleanup of the input could resolve, but i really do not know, testing the thing i could reverse where the problem is, or i should have the complete knowledge of the joke, which unfortunately for me i do not have, especially about emails (so often it require me to test things for long time reversing problems, and so resolving issues, but at high price!).

I would suggest you to test out something like, and about the first instruction i'm not sure it is needed, and nor the second (since i do not see what your output at this point is, may due to extensions or something else), anyway will not do nothing at max:

just after this, OR before (test it) into file /includes/functions_messenger.php:

Code: Select all

// Parse message through template
		$message = trim($this->template->assign_display('body'));
put this:

Code: Select all

$message = strip_tags($message); // remove any tag
$message = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $message); // remove any double space \t and \n
and see what will be the result of the email when sent. The same?
Last edited by axe70 on Mon Sep 14, 2020 3:36 pm, edited 1 time in total.
User avatar
EA117
Registered User
Posts: 2143
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: How to remove line breaks in e-mails sent by phpBB

Post by EA117 »

axe70 wrote:
Mon Sep 14, 2020 12:55 pm
mhh ... May i'm wrong, but are you sure that it is?
I am absolutely, 100% positive that I am not sure this is it. 😜 If there is more to it, then there is more to it. But this was an "unexpected default to 75-character line wrap" (to me, anyway) in functions_messenger.php, and seemed like a reasonable suspect, if not one which will also need to be accounted for before this is over.

axe70 wrote:
Mon Sep 14, 2020 12:55 pm
But for what i know, phpBB emails are not html emails by default. Only plain text. Isn't it?
Correct. I was actually expecting to see that the plain text was being base64 encoded (since almost every other field is), and that the wrap limit intended for the base64-encoded output had somehow been applied to the pre-encoding content as well. But the Content-Type is text/plain in UTF-8, and is not intending to be base64 encoded at all.

Brf wrote:
Mon Sep 14, 2020 1:56 pm
It looks to me that the line-wrap is happening at the template-tag, not any specific character count.
Indeed that is interesting, and I hadn't noticed that. Everything except the last line, I guess, since there is no template break between "click the" and "following link". That one looks like it's the victim of 75 characters, and seems to confirm that there is more than one root cause to chase.

edit: Maybe there is a semi-logical reason for that, if "the template system always does this"? And because the addition of white space doesn't matter in HTML, no one notices or cares. But in a plain text email, we get this result. Digging in to whether templating intentionally does this sounds like no fun at all.
Post Reply

Return to “phpBB Custom Coding”