<p>You could <a href="https://craftcms.com/docs/2.x/plugins/introduction.html" rel="nofollow noreferrer">build a small plugin</a> to hook into Craft's <code>onBeforeSaveEntry</code> event (<a href="https://craftcms.com/docs/2.x/plugins/events-reference.html#entries-onbeforesaveentry" rel="nofollow noreferrer">docs</a>).</p>
<p>Before the entry is saved (and enabled), you'd check if it was previously <code>disabled</code> and its new status is <code>live</code>, if it is, send an email.</p>
<p>The code below should get you going.</p>
<p>Save it as <code>NotifyPlugin.php</code> in a <code>craft/plugins/notify</code> folder.</p>
<pre class="lang-php prettyprint-override"><code>&lt;?php
namespace Craft;

class NotifyPlugin extends BasePlugin
{
    function getName()
    {
        return Craft::t('Notify');
    }

    function getVersion()
    {
        return '1.0';
    }

    function getDeveloper()
    {
        return 'You';
    }

    function getDeveloperUrl()
    {
        return 'http://example.com';
    }

    function init()
    {
        // Trigger only from the Control Panel and Admin users
        if (craft()-&gt;request-&gt;isCpRequest() &amp;&amp; craft()-&gt;userSession-&gt;isAdmin()) {

            // Catch the onBeforeSaveEntry event
            // https://craftcms.com/docs/2.x/plugins/events-reference.html#entries-onbeforesaveentry
            craft()-&gt;on('entries.onBeforeSaveEntry', function(Event $event) {

                // Isolate the entry from the event
                $entry = $event-&gt;params['entry'];

                // The ID of the section currently being saved
                $sectionId = $entry-&gt;sectionId;

                // The ID of the section you want to watch (change that to match your section ID)
                $sectionIdToWatch = 2;

                // Is this a new entry?
                $isNewEntry = $event-&gt;params['isNewEntry'];

                // Is it an entry from the section we are watching and NOT a new entry
                if ($sectionId == $sectionIdToWatch &amp;&amp; !$isNewEntry) {

                    // Fetch the entry before save to use its status for comparison
                    // https://craftcms.com/docs/2.x/plugins/working-with-elements.html#fetching-elements
                    $currentEntry = craft()
                        -&gt;elements
                        -&gt;getCriteria(ElementType::Entry)
                        -&gt;sectionId($sectionId)
                        -&gt;status(null)
                        -&gt;id($entry-&gt;id)
                        -&gt;first();

                    // Entry status before saving
                    $currentEntryStatus = $currentEntry-&gt;status;

                    // New status being saved (from the event)
                    $statusBeingSaved = $entry-&gt;status;

                    // Are we going from disabled to live?
                    if(
                        $currentEntryStatus == BaseElementModel::DISABLED &amp;&amp;
                        $statusBeingSaved == EntryModel::LIVE
                    ) {
                        // Sets $toEmail to the entry's author but change to suit your needs
                        $toEmail = $entry-&gt;author-&gt;email;

                        // Prepare the message
                        $message = new EmailModel();

                        $message-&gt;subject = 'Your notification';
                        $message-&gt;body = 'Email content';
                        $message-&gt;htmlBody = '&lt;html&gt;&lt;body&gt;Email content&lt;/body&gt;&lt;/html&gt;';
                        $message-&gt;toEmail = $toEmail;

                        // Send the message
                        craft()-&gt;email-&gt;sendEmail($message);
                    }
                }
            });
        }
    }
}
</code></pre>
<p>Change <code>$sectionIdToWatch</code> to match your section ID and as is, this will send the email to the entry's author.</p>
<p>As I said, this is just a base to get you going but it should work  :)</p>

CC BY-SA 4.0
2020-10-27T13:32:25.753Z
2020-10-27T13:32:25.753Z
Oli
<p>Running craft 2 on a customer's site. They have users that sign up on the site to receive personalized quotes. What I'd like to do is send an email notification to that user after an admin has enabled the entry that the user created.</p>
<p>I can't find any plugins that do this specifically. I've been trying to customize sprout forms/email to do this, but I'm not having any luck.</p>

<craft2><plugin-guestentries>
Send email notification to user's email when their entry has been enabled
# Send email notification to user's email when their entry has been enabled

(Asked by: username_0 on 2020-10-25)

Running craft 2 on a customer's site. They have users that sign up on the site to receive personalized quotes. What I'd like to do is send an email notification to that user after an admin has enabled the entry that the user created.

I can't find any plugins that do this specifically. I've been trying to customize sprout forms/email to do this, but I'm not having any luck.

**Tags:** craft2, plugin-guestentries


---

## 1 answers

### Answer by username_1 on 2020-10-27. Score: 2 | Accepted answer

You could build a small plugin to hook into Craft's onBeforeSaveEntry event (docs).
Before the entry is saved (and enabled), you'd check if it was previously disabled and its new status is live, if it is, send an email.
The code below should get you going.
Save it as NotifyPlugin.php in a craft/plugins/notify folder.
request->isCpRequest() && craft()->userSession->isAdmin()) {

            // Catch the onBeforeSaveEntry event
            // https://craftcms.com/docs/2.x/plugins/events-reference.html#entries-onbeforesaveentry
            craft()->on('entries.onBeforeSaveEntry', function(Event $event) {

                // Isolate the entry from the event
                $entry = $event->params['entry'];

                // The ID of the section currently being saved
                $sectionId = $entry->sectionId;

                // The ID of the section you want to watch (change that to match your section ID)
                $sectionIdToWatch = 2;

                // Is this a new entry?
                $isNewEntry = $event->params['isNewEntry'];

                // Is it an entry from the section we are watching and NOT a new entry
                if ($sectionId == $sectionIdToWatch && !$isNewEntry) {

                    // Fetch the entry before save to use its status for comparison
                    // https://craftcms.com/docs/2.x/plugins/working-with-elements.html#fetching-elements
                    $currentEntry = craft()
                        ->elements
                        ->getCriteria(ElementType::Entry)
                        ->sectionId($sectionId)
                        ->status(null)
                        ->id($entry->id)
                        ->first();

                    // Entry status before saving
                    $currentEntryStatus = $currentEntry->status;

                    // New status being saved (from the event)
                    $statusBeingSaved = $entry->status;

                    // Are we going from disabled to live?
                    if(
                        $currentEntryStatus == BaseElementModel::DISABLED &&
                        $statusBeingSaved == EntryModel::LIVE
                    ) {
                        // Sets $toEmail to the entry's author but change to suit your needs
                        $toEmail = $entry->author->email;

                        // Prepare the message
                        $message = new EmailModel();

                        $message->subject = 'Your notification';
                        $message->body = 'Email content';
                        $message->htmlBody = 'Email content';
                        $message->toEmail = $toEmail;

                        // Send the message
                        craft()->email->sendEmail($message);
                    }
                }
            });
        }
    }
}

Change $sectionIdToWatch to match your section ID and as is, this will send the email to the entry's author.
As I said, this is just a base to get you going but it should work  :)


---

