pepebe
10/23/2012 - 2:09 PM

Plugin to send email notifications to all members of a user group

Plugin to send email notifications to all members of a user group

<?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);
  }
}
<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>