PDA

View Full Version : Email for PM change


wolfey
09-12-2011, 05:30 PM
OK
I would like to change the body of the email sent to users when a PM is received, currently the email will read:
Dear $touserinfo[username],

You have received a new private message at $vboptions[bbtitle] from $fromusername, entitled "$plaintext_title".

To read the original version, respond to, or delete this message, you must log in here:
$vboptions[bburl]/private.php

This is the message that was sent:
***************
$plaintext_message
***************

I would like to use a custom field I have setup to display the users "Real Name" I Have that inputed into "field2" of their profile
I dont know where/when the $fromusername collects the name...so I cant just put $bbuserinfo[field2] ? Can I

How do I do this?

wolfey
02-13-2012, 10:32 AM
Does anyone know if this can be done?

kh99
02-13-2012, 05:00 PM
The message is sent in function post_save_each() in includes/class_dm_pm.php. It looks like you could create a plugin using hook location pmdata_postsave_recipient to set a new value for $fromusername.

wolfey
02-13-2012, 07:45 PM
Oh ok thats a start, except I have never worked with creating plugins

is there any resources here I can look at to learn a little more, or is there any plugins written close to what I need I can copy from

kh99
02-13-2012, 07:56 PM
Here's the manual page on creating a plugin: https://www.vbulletin.com/docs/html/main/add_plugin (or at least the instructions for using the admincp - it doesn't say much about the coding part). You just need to add some php code in the large text area that sets $fromusername to what you want. If you want to see where it will be executed, look at includes/class_dm_pm.php and search for 'pmdata_postsave_recipient'.

Carpesimia
02-22-2012, 05:10 PM
Hi,

I had the same need so I just got done writing and testing a similar plugin. Here it is:


$ug = $user['usergroupid'];
$admin_message = "";

if (($user['options'] & $this->registry->bf_misc_useroptions['emailonpm']) AND ($ug == 5 OR $ug == 6))
{
$touserinfo =& $user;
$plaintext_parser->set_parsing_language($touserinfo['languageid']);
$admin_message = $plaintext_parser->parse($this->fetch_field('message'), 'privatemessage');

$admin_message = "Message:\n*********\n" . $admin_message . "\n*********\n";
}


Create a new plugin and set it to hook "pmdata_postsave_recipient", as said previously. Paste in the above code. In the IF statement, make sure all of the usergroups you want to get your changes are listed.

In my above example, we normally dont show the contents of the PM. This way people have to come to the website to see what it said. Here, I'm checking if its a mod or an admin, and creating a NEW variable called admin_message. I then go into the pmreceived email template and add the new variable "$admin_message" to the template. This will only have a value if the PM is going to an admin or to a mod.

I hope this helps.

wolfey
02-22-2012, 06:07 PM
OK excellent start! as I have no idea how to creat a plugin using the data I need

So what could I do if I just needed to collect the data from $bbuserinfo[field2]
and have it displayed on the PM when sent

I think yours is a little more advance if I undertsand correctly?

Could I just add $bbuserinfo[field2] to the new variable "$admin_message"

Again, I am just trying to display the users real name that I have set in field2 to any PM sent by this usergroup

I really appreciate your help!

--------------- Added 1329938407 at 1329938407 ---------------

Sorry I know I got that wrong, you are setting the value of $admin_message only if its a mod or admin user

How could I use that to display the field 2?

Carpesimia
02-22-2012, 06:55 PM
Well, first you're gonna want to find the group of the user SENDING your PM. This might be as easy as checking:

$vbulletin->userinfo['usergroupid'];

So in MY example, you would test for $vbulletin->userinfo['usergroupid'] == ### for the if. This makes sure that the logic is ONLY done for people of the usergroup you want. Then, make a variable (using admin_message is ok, since it is not used otherwise) and give it the value of $bbuser['field2'].

Should be straight forward, so long as those 2 variables are in scope. You may need to globalize them.

Anyone else wanna weigh in here?

wolfey
02-22-2012, 07:13 PM
OK thanks!
I am going to try this now

This will be awesome if it works...we have some admins that dont knnow who is sending them emails, because of the userid handle

--------------- Added 1329942354 at 1329942354 ---------------

OK, I feel dumb
.I am stuck on a small detail...

Where am I adding this new variable? Looking around cant find "pmreceived"

OR can I just put the $bbuserinfo[field2] right in the hook?

sorry to be a pain!

wolfey
04-03-2012, 09:23 AM
Cant get it to work, no errors just the results arent there

damn