Sending message body in e-mail notifications

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
executifs
Registered User
Posts: 14
Joined: Wed Mar 26, 2014 1:45 am

Sending message body in e-mail notifications

Post by executifs »

Hi everyone.
I've recently been trying to mod my phpBB 3.1 forum, so that the post contents are also displayed in e-mail notifications. After some digging, I have made the following modifications:

Code: Select all

diff a/phpbb/notification/type/topic.php b/phpbb/notification/type/topic.php
index 5f57087..c12746f 100644
--- a/topic.php
+++ b/topic_mod.php
@@ -202,6 +202,7 @@ class topic extends \phpbb\notification\type\base
          'AUTHOR_NAME'            => htmlspecialchars_decode($username),
          'FORUM_NAME'            => htmlspecialchars_decode($this->get_data('forum_name')),
          'TOPIC_TITLE'            => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
+         'POST_TEXT'               => htmlspecialchars_decode(censor_text($this->get_data('post_text'))),
 
          'U_TOPIC'               => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}",
          'U_VIEW_TOPIC'            => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}",
@@ -280,6 +281,8 @@ class topic extends \phpbb\notification\type\base
       $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
 
       $this->set_data('forum_name', $post['forum_name']);
+      
+      $this->set_data('post_text', $post['post_text']);
 
       $this->notification_time = $post['post_time'];
I was hoping to use the {POST_TEXT} variable in e-mail templates, but it doesn't seem to work. I must be missing something, because it seems to me that $post['post_text'] shouldn't be null, as it is set in includes/functions_posting.php on line 2284:

Code: Select all

	// Send Notifications
	$notification_data = array_merge($data, array(
		'topic_title'		=> (isset($data['topic_title'])) ? $data['topic_title'] : $subject,
		'post_username'		=> $username,
		'poster_id'			=> $poster_id,
		'post_text'			=> $data['message'],
		'post_time'			=> $current_time,
		'post_subject'		=> $subject,
	));
Does anyone know what I'm missing?
Thanks in advance!
Last edited by Oyabun1 on Fri Oct 16, 2015 9:47 am, edited 1 time in total.
Reason: Moved form 3.1.x Extension Requests
User avatar
KaileyT
Community Team Member
Community Team Member
Posts: 2933
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Sending message body in e-mail notifications

Post by KaileyT »

Try htmlspecialchars_decode(censor_text($this->get_data('message'))), and let us know the result.
Kailey Truscott - Community Team
executifs
Registered User
Posts: 14
Joined: Wed Mar 26, 2014 1:45 am

Re: Sending message body in e-mail notifications

Post by executifs »

It doesn't look like it's working either.
executifs
Registered User
Posts: 14
Joined: Wed Mar 26, 2014 1:45 am

Re: Sending message body in e-mail notifications

Post by executifs »

I still haven't figured it out... Has anyone else got an idea?
StephenGentleman
Registered User
Posts: 1
Joined: Tue Oct 13, 2015 8:34 pm

Re: Sending message body in e-mail notifications

Post by StephenGentleman »

Hi. I've just started using phpBB recently to admin a club forum. I'm very much a phpBB novice (though have done loads of other coding), and am looking for a solution to this too. Has anyone cracked it yet? Would be great to get the post_text into the email to avoid users having to log in so much!

Thanks.
User avatar
Lumpy Burgertushie
Registered User
Posts: 68554
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Sending message body in e-mail notifications

Post by Lumpy Burgertushie »

StephenGentleman wrote:Hi. I've just started using phpBB recently to admin a club forum. I'm very much a phpBB novice (though have done loads of other coding), and am looking for a solution to this too. Has anyone cracked it yet? Would be great to get the post_text into the email to avoid users having to log in so much!

Thanks.
don't you think that kind of defeats the whole purpose of a web based bulletin board script?

the whole point of web based scripts like phpbb was to replace the old fashioned mailinglist type of discussions.

it seems that if one wants one of those, there are still some archived scripts of that type around.

also, people do not have to "login so much" with phpbb. you log in once, tell it to remember you, don't log out. then each time you visit the board it logs you in automatically without you even realizing it.


robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
SiB57
Registered User
Posts: 2
Joined: Thu Feb 19, 2015 6:18 pm

Re: Sending message body in e-mail notifications

Post by SiB57 »

Just throwing this out there, it's the number one requested feature from users of my forum as well. While I'm fine with "logging in" a lot (and on mobile, logins do NOT seem to stick, that's another issue I'm working on that's driving my users crazy.) People who are used to using other forum software such as vBulletin are used to getting the text of at least the first reply in their email notification that something has been replied to. And when there's a PM, they really want the message.

I don't do any PHP work or I'd take a look myself, but I'm just letting it be known that it's a big feature request by a lot of users.
alex001
Registered User
Posts: 5
Joined: Mon Feb 15, 2016 3:35 pm

Re: Sending message body in e-mail notifications

Post by alex001 »

Tried this for 3.1.7 which i've installed this weekend. I'm not really firm with php and this hundreds of files of phpBB... but if you want to implement it directly into the code you have to modify

phpbb/notification/type/post.php

Search (around line 375)

Code: Select all

public function create_insert_array($post, $pre_create_data = array())
	{
		$this->set_data('poster_id', $post['poster_id']);
		$this->set_data('topic_title', $post['topic_title']);
		$this->set_data('post_subject', $post['post_subject']);
		$this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
		$this->set_data('forum_id', $post['forum_id']);
		$this->set_data('forum_name', $post['forum_name']);
		$this->notification_time = $post['post_time'];
		
		//add a new line here
 	  $this->set_data('post_text', $post['post_text']);

Search (around line 262)

Code: Select all

return array(
	'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'))),
	
//add a new line
   'POST_MESSAGE'        	=> htmlspecialchars_decode(censor_text($this->get_data('post_text'))),


Then you can use {POST_MESSAGE} in the topic_notify.txt template file to insert the message text. I think the same has to be done with the file phpbb/notification/type/topic.php and the forum_notify.txt template (?).

But things like BB-Code or attachments need to be stripped out or "transformend" in the POST_MESSAGE text before it can be sent as email. Is there a function anywhere to to that? Or can someone do that? :)

Regards
Alex
User avatar
Sajaki
Registered User
Posts: 1379
Joined: Mon Mar 02, 2009 1:41 pm
Location: Amsterdam
Contact:

Re: Sending message body in e-mail notifications

Post by Sajaki »

I think this would be an extension request. core code changes (MODS) aren't done anymore.
petsits
Registered User
Posts: 46
Joined: Sat Mar 31, 2007 6:31 pm

Re: Sending message body in e-mail notifications

Post by petsits »

Did you find such a function?
Post Reply

Return to “Extension Writers Discussion”