Cms: FR: Config option to prevent emails from sending

Created on 10 Jul 2019  路  4Comments  路  Source: craftcms/cms

Description

We just updated to 3.2 and for some reason the after entry save event was triggered seven times for a disabled entry with the event saying the entry was new. This in turn triggered an email to be sent 7 times to _a lot_ of people referencing this disabled entry.

It would be really useful to have a config option that would prevent emails from being sent in certain environments, as a precaution against accidentally sending emails from development sites!

Most helpful comment

Most likely those new entries were drafts/revisions being created for existing entries, as all drafts & revisions in 3.2 are stored as actual elements.

In your afterSave handler, you can check whether the entry is a draft/revision by calling ElementHelper::isDraftOrRevision():

use craft\helpers\ElementHelper;

// ...

if (ElementHelper::isDraftOrRevision($entry) {
    return;
}

All 4 comments

@Tam Would testtoemailaddress not work for you? You can set it to a test email for your dev sites.

Configures Craft to send all system emails to a single email address, or an array of email addresses for testing purposes.

https://docs.craftcms.com/v3/config/config-settings.html#testtoemailaddress

@john-henry It absolutely does! Don't know how I missed that, thanks!

Most likely those new entries were drafts/revisions being created for existing entries, as all drafts & revisions in 3.2 are stored as actual elements.

In your afterSave handler, you can check whether the entry is a draft/revision by calling ElementHelper::isDraftOrRevision():

use craft\helpers\ElementHelper;

// ...

if (ElementHelper::isDraftOrRevision($entry) {
    return;
}

Thanks @brandonkelly!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angrybrad picture angrybrad  路  3Comments

angrybrad picture angrybrad  路  3Comments

lukebailey picture lukebailey  路  3Comments

darylknight picture darylknight  路  3Comments

leigeber picture leigeber  路  3Comments