Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Phphelp in August 23, 2013, 09:46:54 VORMITTAG

Titel: If a user gives someone karma send them an email letting them know.
Beitrag von: Phphelp in August 23, 2013, 09:46:54 VORMITTAG
I remember reading a post on here that someone wanted to do this..

Here's the code you will need to customize it based on the email message you want to send out.

In your sources/karma.php

Add this function

// Send the karma person a lovely email.
function emailKarma($template, $replacements = array(), $additional_recipients = array())
{
global $smcFunc, $sourcedir, $user_info;

// We certainly want this.
require_once($sourcedir . '/Subs-Post.php');

$request = $smcFunc['db_query']('', '
SELECT id_member, member_name, real_name, email_address
FROM {db_prefix}members
WHERE (id_member = ' . $_REQUEST['uid'] . ' )');

while ($row = $smcFunc['db_fetch_assoc']($request))
{

  $headers = 'PHP Help' . "\r\n";

// Then send the actual email.
sendmail($row['email_address'], $user_info['username'] . ' just gave you Karma on PHPHelp.com', $user_info['username'] . ' thought one of your posts was worthy of good karma! Thanks for contributing at www.phphelp.com/forum/', $headers);


}
$smcFunc['db_free_result']($request);

}


Next Find this..
// Change by one.
updateMemberData($_REQUEST['uid'], array($dir == 1 ? 'karma_good' : 'karma_bad' => '+'));


And under it add this.

//Send member an email here that's being updated.
emailKarma();
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: shadow82x in August 23, 2013, 10:39:36 VORMITTAG
I moved this over to the right forum. :)
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: Phphelp in August 23, 2013, 11:10:28 VORMITTAG
Thanks, I didn't know where to post my minor mods! I do now!
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: PierreP_whited00r_com in August 26, 2013, 11:48:34 NACHMITTAGS
Can a user opt out of that as it can be annoying if a posts gets dozens of Karma's.
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: Phphelp in August 28, 2013, 08:37:48 NACHMITTAGS
Not the way it's currently coded, would need to build it into the notification system, I didn't think about that.
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: PierreP_whited00r_com in September 02, 2013, 12:21:14 VORMITTAG
No worries in our case because only the moderators can give Karma in our forum and we are not liberal with that.

I am sorry for not saying thank you in my post above for your neat idea. :-[

After we fix some stability issues we will give your script a try & report here.
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: Biology Forums in September 16, 2013, 07:38:34 NACHMITTAGS
Very nice!
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: MidasBalaa in November 06, 2013, 10:09:00 VORMITTAG
Very good. Keeps people coming back to the forum
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: playtony in Oktober 12, 2014, 12:42:30 NACHMITTAGS
Is it possible to have this activated just for particular users? I don't want that every user on our forum get this mail, but I would like that my administrators get it?
Titel: Re: If a user gives someone karma send them an email letting them know.
Beitrag von: Kindred in Oktober 12, 2014, 01:33:33 NACHMITTAGS
http://custom.simplemachines.org/mods/index.php?mod=192