having email notification contain post body?

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Scam Warning
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
gregveres
Registered User
Posts: 18
Joined: Mon Jan 01, 2007 8:58 pm

having email notification contain post body?

Post by gregveres »

Hi,

I have looked everywhere I can think of and I haven't found a single reference to this. I can subscribe to a topic or a forum and then as soon as somebody posts something new, I get an email saying that something new has been posted, and I should go visit the forum.

What I would like to do is have the body of the post included in the email. Is this possible? If it is not currently possible, can somebody point to the proper file so that I can go try to add it?

Thanks
Greg
fpbaum
Registered User
Posts: 52
Joined: Mon Aug 20, 2007 10:53 pm

Re: having email notification contain post body?

Post by fpbaum »

***EDITED***forgot to add code to strip bbcode from post text
You have to change the email templates as well as add some code to insert the post message into the templates. The email templates are just text files with place holders that get dynamically replaced with stuff like the forum name, post subject, etc...so you just have to create a new place holder, in your case "{POST_TEXT}" and then fill it.

Add post text to email notifications. Edit the files...
  • /includes/functions_posting.php
    Around line 2405 strip bbcode from $data['message'] and pass it to the user_notification() function call...

    Code: Select all

    <?php  
    // Send Notifications
    if ($mode != 'edit' && $mode != 'delete' && ($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])))
    {
        //remove bbcode from text
        $stripped_post_text = $data['message'];
        strip_bbcode($stripped_post_text, $data['bbcode_uid']);
        user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $stripped_post_text);       
    }
                  
    Around line 1096 added parameter $post_text='' (empty string as default to make it optional, in case its called from elsewhere) to parameter list...

    Code: Select all

    <?php 
    /**
    * User Notification
    */
    function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id, $post_text='')
    {
        global $db, $user, $config, $phpbb_root_path, $phpEx, $auth;              
    Around line 1255 added the array key/value pair 'POST_TEXT' => htmlspecialchars_decode($post_text), ...

    Code: Select all

    <?php 
    $messenger->assign_vars(array(
        'USERNAME'        => htmlspecialchars_decode($addr['name']),
        'TOPIC_TITLE'    => htmlspecialchars_decode($topic_title),
        'FORUM_NAME'    => htmlspecialchars_decode($forum_name),
        'POST_TEXT'        => htmlspecialchars_decode($post_text),
    
        'U_FORUM'                => generate_board_url() . "/viewforum.$phpEx?f=$forum_id",
        'U_TOPIC'                => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id",
        'U_NEWEST_POST'            => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id",
        'U_STOP_WATCHING_TOPIC'    => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&unwatch=topic",
        'U_STOP_WATCHING_FORUM'    => generate_board_url() . "/viewforum.$phpEx?f=$forum_id&unwatch=forum",
    ));
                  
  • /language/en/email/forum_notify.txt, added "{POST_TEXT}" (with quotation marks) and some spacing...place holder post text
  • /language/en/email/newtopic_notify.txt, added "{POST_TEXT}" (with quotation marks) and some spacing...place holder post text
  • /language/en/email/topic_notify.txt, added "{POST_TEXT}" (with quotation marks) and some spacing...place holder post text
Last edited by fpbaum on Mon May 19, 2008 3:00 pm, edited 1 time in total.
gregveres
Registered User
Posts: 18
Joined: Mon Jan 01, 2007 8:58 pm

Re: having email notification contain post body?

Post by gregveres »

cool thanks. I will give that a try.

Greg
Kerrith
Registered User
Posts: 490
Joined: Mon Mar 28, 2005 10:16 am
Location: Pahoa, Hawaii

Re: having email notification contain post body?

Post by Kerrith »

Hi Greg,

Did you try this? If yes, did it work?

I got lost at
/language/en/email/forum_notify.txt, added "{POST_TEXT}" (with quotation marks) and some spacing...place holder post text
/language/en/email/newtopic_notify.txt, added "{POST_TEXT}" (with quotation marks) and some spacing...place holder post text
/language/en/email/topic_notify.txt, added "{POST_TEXT}" (with quotation marks) and some spacing...place holder post text
Thanks,

Kerry
fpbaum
Registered User
Posts: 52
Joined: Mon Aug 20, 2007 10:53 pm

Re: having email notification contain post body?

Post by fpbaum »

Sorry, that last part wasn't too clear. Those text files are the email templates. Each contains plain text like...

Code: Select all

Subject: New topic notification - "{FORUM_NAME}"

Hello {USERNAME},

You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new topic since your last visit, "{TOPIC_TITLE}".  

"{POST_TEXT}"

You can use the following link to view forum, no more notifications will be sent until you visit the forum.

{U_FORUM}

If you no longer wish to watch this forum you can either click the "Unsubscribe forum" link found in the forum above, or by clicking the following link:

{U_STOP_WATCHING_FORUM}

{EMAIL_SIG}
The stuff in brackets are placeholders. The function messenger->assign_vars() is used to add a key value pair for POST_TEXT=>$post_text which the messenger class later uses to do a find and replace of all the place holders before sending the email. I added the place holder "{POST_TEXT}" to this and the other two files so that the code changes from functions_posting.php would pop the post text in there. Just reformat the rest of the plain text however you want the email to be displayed.
Kerrith
Registered User
Posts: 490
Joined: Mon Mar 28, 2005 10:16 am
Location: Pahoa, Hawaii

Re: having email notification contain post body?

Post by Kerrith »

Hi fpbaum,

Since posting I discovered newpost2mail_beta9 which I installed but can't get to work. I'm not getting a email notifcation of a new post or a reply, neither as a new registered user or as admin.

Thank you,

Kerry
gregveres
Registered User
Posts: 18
Joined: Mon Jan 01, 2007 8:58 pm

Re: having email notification contain post body?

Post by gregveres »

Kerrith wrote:Hi fpbaum,

Since posting I discovered newpost2mail_beta9 which I installed but can't get to work. I'm not getting a email notifcation of a new post or a reply, neither as a new registered user or as admin.

Thank you,

Kerry

Where did you find that? I did a google search for newpost2mail_beta9 and only found a reference to this thread.

Thanks
Greg
Kerrith
Registered User
Posts: 490
Joined: Mon Mar 28, 2005 10:16 am
Location: Pahoa, Hawaii

Re: having email notification contain post body?

Post by Kerrith »

Hi Greg,

Here's Stefan's web site http://henmedia.de/index.php?option=com ... &Itemid=35 The most recent version is beta11 (as of 11:07PM 1/24/08).

Here's the mod's forum http://www.phpbb.com/community/viewtopi ... 5#p4032725.

I'm still trying to get it to work. Others have so I'm thinking it's a phpBB3.0 ACP setting problem. I just now myself found and downloaded v11 so I'm going to work with it and see what happens.
Last edited by Kerrith on Fri Jan 25, 2008 9:53 pm, edited 1 time in total.
gregveres
Registered User
Posts: 18
Joined: Mon Jan 01, 2007 8:58 pm

Re: having email notification contain post body?

Post by gregveres »

Well last night I followed fpbaum's instructions last night but my site stopped sending email for some reason. I have to debug that now. :( I put all the files back and it still doesn't send email so something else must have gone wrong - probably my linux box's setup.

Thanks for the links to the other mod though I will check it out too.

Thanks
Greg
Kerrith
Registered User
Posts: 490
Joined: Mon Mar 28, 2005 10:16 am
Location: Pahoa, Hawaii

Re: having email notification contain post body?

Post by Kerrith »

Your'e most welcome Greg,

Kerry
Ned_K
Registered User
Posts: 4
Joined: Thu Mar 13, 2008 4:39 am

Re: having email notification contain post body?

Post by Ned_K »

Hi fpbaum

I have phpbb rcp5 installed. I am trying to use the information u provided in this thread to include mail text in the body of my forum notification emails. I don't seem to have the function function user_notification, required for the second step in your modification. Any clues??
fpbaum
Registered User
Posts: 52
Joined: Mon Aug 20, 2007 10:53 pm

Re: having email notification contain post body?

Post by fpbaum »

I'm guessing RC5 code didn't include that function. You really should upgrade to the gold release...but if not then you'll have to follow the code until you find where $messenger->assign_vars is called (assuming that exists in your version) and add POST_TEXT as a variable, as in the the last code block in my example.

I guess lots of other code could be different, so make sure my logic makes sense in RC5.
fpbaum
Registered User
Posts: 52
Joined: Mon Aug 20, 2007 10:53 pm

Re: having email notification contain post body?

Post by fpbaum »

...and FYI, I just realized that URLs inside bbcode URL tags don't parse correctly for the email body. They display ass as http&#58;//www&#46;domain&#46;com. I'm sure it's my misuse of the bbcode parsing functions since it only happens when the url has the form [url]http://www.domain.com[/url], but not when you use [url=http://www.domain.com]link text[/url] or just http://www.domain.com as plain text. I tried htmlspecialchars_decode and html_entities_decode but nothing works! I don't get it but no time to fool with it.
aavaliani
Registered User
Posts: 2
Joined: Mon Apr 14, 2008 10:50 am

Re: having email notification contain post body?

Post by aavaliani »

thanks fpbaum! It worked nicely.

Archil
fpbaum
Registered User
Posts: 52
Joined: Mon Aug 20, 2007 10:53 pm

Re: having email notification contain post body?

Post by fpbaum »

no problem, and if you are inclined to fix the url problem I mentioned and figure it out, please do post that since I still haven't had time to look at it.

Return to “[3.0.x] Support Forum”