Use of HTML in notification emails - Board watch
Use of HTML in notification emails
Is there a way to use basic HTML tags / code in the notification emails? I found the text files in the language/en/email directory, but when I tried to use, for example, a <b> tag it reads it as text instead of a tag.
Thanks!
Thanks!
-
- Registered User
- Posts: 1
- Joined: Tue May 22, 2012 8:28 pm
Re: Use of HTML in notification emails
This mod doesn't touch phpbb3's regular emailer functions, so you would need to mod those functions in some way. If you google for phpbb3 html email you may find something on this. Otherwise, you could post in the mod request forum (viewforum.php?f=72).
-
- Registered User
- Posts: 6266
- Joined: Sun Feb 22, 2004 9:34 pm
- Location: NYC
- Name: Alan
Re: Use of HTML in notification emails
Not without massively changing the phpBB code, which I would think was well outside the scope of this MOD.
There is no defined standard for HTML for use in email, every client handles it a bit differently, which can lead to various problems. Therefore, phpBB sends all emails as plain text because that is the most compatible with the widest range of email clients and servers.
There is no defined standard for HTML for use in email, every client handles it a bit differently, which can lead to various problems. Therefore, phpBB sends all emails as plain text because that is the most compatible with the widest range of email clients and servers.
Support Request Template
3.0.x: Knowledge Base ★ Styles Support ★ MOD Requests
3.1.x: Knowledge Base ☢ Styles Support ☢ Extension Requests
3.0.x: Knowledge Base ★ Styles Support ★ MOD Requests
3.1.x: Knowledge Base ☢ Styles Support ☢ Extension Requests
-
- Former Team Member
- Posts: 23162
- Joined: Sun May 17, 2009 1:05 pm
- Location: Australia
- Name: Bill
Re: Use of HTML in notification emails
Thanks, Bill. I know nothing about email encoding and I'm sure you're right but I'm curious: why is it complicated? I would have guessed you could look for the line that adds "content:text" to the header (perhaps in includes/functions_messenger.php though I haven't looked) and change it to add "content:text/html" and then tinker with the email templates to stick in whatever html you want. I gather it's way harder than that but why is that?
-
- Registered User
- Posts: 6266
- Joined: Sun Feb 22, 2004 9:34 pm
- Location: NYC
- Name: Alan
Re: Use of HTML in notification emails
To be honest, I'm not really sure what is involved. I just know that in the past I've read that it is not a simple thing to change. Although, having said that, there is at least one MOD (phpBB Digests) that can send its emails as HTML format, so maybe it isn't that difficult.
Support Request Template
3.0.x: Knowledge Base ★ Styles Support ★ MOD Requests
3.1.x: Knowledge Base ☢ Styles Support ☢ Extension Requests
3.0.x: Knowledge Base ★ Styles Support ★ MOD Requests
3.1.x: Knowledge Base ☢ Styles Support ☢ Extension Requests
-
- Former Team Member
- Posts: 23162
- Joined: Sun May 17, 2009 1:05 pm
- Location: Australia
- Name: Bill
Re: Use of HTML in notification emails
I just tried the following and it seems to work:
I don't know what other bad side effects there may be to doing this (and maybe it won't work right for all smtp setups?). Also, once you do that ALL emails sent by the board will be in html, so you would either have to carefully go through all emails templates and add html as needed (e.g. adding <br /> where necessary) or you would have to add a little code to ensure that the unchanged line (with text/plain) is used whenever an email other than a post notification is sent.
Code: Select all
OPEN
includes/functions_messenger.php
FIND
$headers[] = 'Content-Type: text/plain; charset=UTF-8'; // format=flowed
REPLACE WITH'
$headers[] = 'Content-Type: text/html; charset=UTF-8'; // format=flowed
I don't know what other bad side effects there may be to doing this (and maybe it won't work right for all smtp setups?). Also, once you do that ALL emails sent by the board will be in html, so you would either have to carefully go through all emails templates and add html as needed (e.g. adding <br /> where necessary) or you would have to add a little code to ensure that the unchanged line (with text/plain) is used whenever an email other than a post notification is sent.
-
- Registered User
- Posts: 6266
- Joined: Sun Feb 22, 2004 9:34 pm
- Location: NYC
- Name: Alan
Re: Use of HTML in notification emails
Oyabun1 wrote:there is at least one MOD (phpBB Digests) that can send its emails as HTML format, so maybe it isn't that difficult.
Just skimmed that digest mod and it looks to me like the only thing it does in order to switch an email to html is to make the change to functions_messenger.php that I describe in my last post. But I see that it allows each user to choose for himself whether to receive emails in html or plain text. To add that option is considerably more involved, and since the email clients for some users will only recognize text it may be that doing this is important (I'm not sure what an html email will look like on a client that doesn't display html...will it strip out the tags or will it show them in an ugly way?).
Anyway, evolve416, if you know a bit of coding you could probably follow the digest mod as a guide and incorporate the relevant code into your board to use with boardwatch (not sure it's really worth it, though).
-
- Registered User
- Posts: 6266
- Joined: Sun Feb 22, 2004 9:34 pm
- Location: NYC
- Name: Alan
Re: Use of HTML in notification emails
Its silly that PHP does not leave message formats up tot he user but instead arbitrarily forces it on you, but regardless here is an answer to the issue that is expanded a tad more from the above modification to allow multipart emails for backwards compatibility.
in Functions_messanger.php line 440 make the following change:
In same file scroll to bottom and add following function:
Now just above, at line 1725, change it to read:
This will do a couple things;
First off, if a message is not formatted for HTML, meaning it is plain text, it will insert line breaks to fix the format.
Second, if you HAVE added HTML to your message it will now be seen as actual HTML and not plain text
Third, on older message readers it will revert to plain text and strip HTML from HTML formatted messages.
Enjoy.
in Functions_messanger.php line 440 make the following change:
Code: Select all
$headers[] = 'Content-Type: multipart/alternative; boundary=c4d5d00c4725d9ed0b3c8b; charset=iso-8859-1'; // format=flowed
//$headers[] = 'Content-Transfer-Encoding: 8bit'; //This is commented out because it will be set later
In same file scroll to bottom and add following function:
Code: Select all
function CreateMultiPartBody($body)
{
$PlainText = wordwrap(utf8_wordwrap(strip_tags($body)), 997, "\n", true);
$HtmlText = $body;
if ($body == strip_tags($body))
{
$HtmlText = str_replace("\n", "<br/>\n", $body);
}
$MultiPartBody = "
--c4d5d00c4725d9ed0b3c8b
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit";
$MultiPartBody .= $PlainText;
$MultiPartBody .= "
--c4d5d00c4725d9ed0b3c8b
Content-Type: text/html; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit";
$MultiPartBody .= $HtmlText;
$MultiPartBody .= "
--c4d5d00c4725d9ed0b3c8b--";
return $MultiPartBody;
}
Now just above, at line 1725, change it to read:
Code: Select all
$result = $config['email_function_name']($to, mail_encode($subject, ''), CreateMultiPartBody($msg), $headers);
This will do a couple things;
First off, if a message is not formatted for HTML, meaning it is plain text, it will insert line breaks to fix the format.
Second, if you HAVE added HTML to your message it will now be seen as actual HTML and not plain text
Third, on older message readers it will revert to plain text and strip HTML from HTML formatted messages.
Enjoy.
-
- Registered User
- Posts: 27
- Joined: Thu Mar 05, 2015 5:38 pm
Re: Use of HTML in notification emails
Can you help?asinshesq wrote:I just tried the following and it seems to work:
I don't know what other bad side effects there may be to doing this (and maybe it won't work right for all smtp setups?). Also, once you do that ALL emails sent by the board will be in html, so you would either have to carefully go through all emails templates and add html as needed (e.g. adding <br /> where necessary) or you would have to add a little code to ensure that the unchanged line (with text/plain) is used whenever an email other than a post notification is sent.Code: Select all
OPEN includes/functions_messenger.php FIND $headers[] = 'Content-Type: text/plain; charset=UTF-8'; // format=flowed REPLACE WITH' $headers[] = 'Content-Type: text/html; charset=UTF-8'; // format=flowed
Html email is doing fine but for some reason email clients can not recognize email subject within the email template. Do you know how I can resolve this?
When you stop learning, stop listening, stop looking and asking questions, always new questions, then it is time to die. Lillian Smith
-
- Registered User
- Posts: 1032
- Joined: Fri Apr 30, 2004 7:18 pm