Skip to content

Instantly share code, notes, and snippets.

@Mark-H
Created March 8, 2012 14:11
Show Gist options
  • Save Mark-H/2001155 to your computer and use it in GitHub Desktop.
Save Mark-H/2001155 to your computer and use it in GitHub Desktop.
Plugin to send email notifications to all members of a user group
<p>Hi there!</p>
<p>The resource [[+pagetitle]] (ID: [[+id]]) has been [[+mode]].</p>
<p>You can login to the manager at www.mysite.com/manager/ to review and if needed publish the resource.</p>
<p>Thank you!</p>
<?php
// untested
// Update these if you have to
$usergroup = 1; // user group ID (1=admin)
$chunkname = 'notificationtpl'; // name of chunk for the email notification
$emailoptions = array(
'from' => $modx->getOption('emailsender'),
'fromName' => 'Resource Notification',
'subject' => 'Nofication of Created or Updated Resource',
'html' => true,
);
// No need to update below (unless I typo-ed)
$placeholders = $resource->toArray();
$placeholders['mode'] = ($mode == 'upd') ? 'updated' : 'created';
$message = $modx->getChunk($chunkname,$placeholders);
$userIds = $modx->getCollection('modUserGroupMember', array('user_group' => $usergroup));
foreach ($userIds as $userId) {
$user = $modx->getObject('modUser',$userId->get('member'));
if ($user) {
$user->sendEmail($message, $emailoptions);
}
}
@tommls
Copy link

tommls commented Mar 8, 2012 via email

@pepebe
Copy link

pepebe commented Oct 23, 2012

Found your gist and it was exactly what I needed. Thanks!!!

@sebastian-marinescu
Copy link

This is exactly what I needed. Many thanks for this exceptional ground-work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment