8

Is it possible for a user group to be notified by email when a post is submitted using either the backend or a form on the front end?

4 Answers 4

7

Currently there isn't a native way to do this, but you could write a plugin which would work like this:

.

Quick-and-Dirty:

public function init()
{
    parent::init();

    //Event: onSaveEntry
    craft()->on('entries.saveEntry', function(Event $event) {

        //Get all users from UserGroup
        $user_criteria = craft()->elements->getCriteria(ElementType::User);
        $user_criteria->groupId = '1';
        $users = $user_criteria->find();

        //Send to each User
        foreach ($users as $user) {
            //Send Mail
            $email = new EmailModel();
            $email->toEmail = $user->email;
            $email->subject = 'Heyyyyy';
            $email->body    = 'How you doin?';

            craft()->email->sendEmail($email);
        }
    });
}
3
  • Thanks for this Victor, I am trying to get into simple plugin development so this is really useful. Is there are very simple boilerplate set of example files to learn how to add what you have given me and make it work as a plugin?
    – Gareth
    Jun 22, 2014 at 9:24
  • 1
    Except for the $user_criteria part, which I got from the 'G+ Dev Group' the rest of the code is copied out of the docs (see my links in the list above). Also 'reverse-engineering' other peoples plugins explains a lot (list: straightupcraft.com/craft-plugins ). Otherwise it's 'Try & Error' or asking ;)
    – Victor
    Jun 22, 2014 at 10:28
  • 1
    Oh, and check out: buildwithcraft.com/docs/plugins/introduction which will help you get started. The init() functions goes into the main plugin-file.
    – Victor
    Jun 22, 2014 at 10:30
6

For those that are looking for a plugin that simply notifies users (without all the overhead), take a look at Brief. It's a super-light plugin that simply notifies users whenever a new entry is added to a Section.

If anybody has a specific need for it, I'd be glad to add features.

More information: Brief

1
  • 2
    Nice work! You should submit it to Straight Up Craft, the official unofficial plugins listing.
    – Lindsey D
    Sep 17, 2015 at 5:17
4

Alternatively, you could get in touch with Ben Parizek of Barrel Strength Design who has a plugin called Sprout Email. Currently in beta but you can request a preview.

I am using it as we speak.

0
1

Or, have a look at Postmaster, which works a treat!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.