2.5.10+ Getting new PM to send Notification Email
  • 2021/1/26 16:57

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26

I was running an old 2.2.4RC2 website and recently converted over to XOOPS 2.5.11-Beta1

I've had to weave back in all my prior hacks/mods to restore some of the functionality I had before. One of those was getting a notification when a new PM was sent. I couldn't figure out why this wasn't working. Then looking at the code in pmlite.php I noticed this TODO comment at around line 86:

// @todo: Send notification email if user has selected this in the profile

So I made two changes to enabled this functionality again.

1) Change the above to read:

// Added by BigKev73 to enabled email on new PM
$sUser $member_handler->getUser(XoopsRequest::getInt('to_userid'0'POST'));
$rez=  $pm_handler->sendPMEmail($pm$sUser);

2) At this code into ..modules/pm/class/message.php after the sendEmail function (around line 191):

//added by BigKev73 to renable sending a email when a new PM is created
public function sendPMEmail(PmMessage $pmXoopsUser $user)

        if (
is_object($user)) {
$from = new XoopsUser($pm->getVar('from_userid'));
$to   = new XoopsUser($pm->getVar('to_userid'));
$msg 'You received a new Private Message from ' $from->getVar('name');
$msg .= "nn";
$msg .= "Sent: " formatTimestamp($pm->getVar('msg_time'));
$msg .= "n";
$msg .= "n Subject: " $pm->getVar('subject') . "n";
$msg .= "n Message: " strip_tags(str_replace(array('<p>''</p>''<br>''<br>'), "n"$pm->getVar('msg_text'))) . "nn";
$msg .= "--------------n";
$msg .= $xoopsConfig['sitename'] . ': ' XOOPS_URL "n";
$xoopsMailer xoops_getMailer();
$xoopsMailer->setSubject(sprintf("You received a Private Message on " $xoopsConfig['sitename']));
        }else {

A couple of notes:

1) You can obviously use variable tokens instead of the literal message strings I am using
2) I am using users 'name' on my website instead of uname. So change the
$msg 'You received a new Private Message from ' $from->getVar('name');
$msg 'You received a new Private Message from ' $from->getVar('uname'); if you want the default.

3) I'm also using a specific noreply@sitename.com email address vs the normal admin email when sending things out. So if you want to change the email, then change the following lines:



4) This is basically a modified version of the sendEmail function, that is taylored with a more tailored message. This could be wired up to a template as needed.

Hope this helps!


Re: 2.5.10+ Getting new PM to send Notification Email
  • 2021/1/27 8:59

  • Mamba

  • Moderator

  • Posts: 11277

  • Since: 2004/4/23

Thank you for sharing! This might be a useful feature to add to Core.
I've sent email to Richard about it.
Use 2.5.10 | Docs | Modules | Bugs


Who's Online

77 user(s) are online (50 user(s) are browsing Support Forums)

Members: 0

Guests: 77



Goal: $100.00
Due Date: Feb 28
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits