I use Guest Entries plugin to add information, and I need to send some message to user who filled the form to email. Can you show me an example of how I can do this?
-
Is this Guest Entries 1 for Craft 2 or Guest Entries 2 for Craft 3? – Brad Bell Aug 13 '18 at 3:32
-
it is Guest Entries 2 for Craft 3 – Alex Ryhluk Aug 13 '18 at 5:58
You could do this with a small plugin that listened to the Guest Entries afterSaveEntry event.
The logic would look something like this:
use craft\guestentries\controllers\SaveController;
use craft\guestentries\events\SaveEvent;
use yii\base\Event;
// ...
Event::on(SaveController::class, SaveController::EVENT_AFTER_SAVE_ENTRY, function(SaveEvent $e) {
// Grab the entry
$entry = $e->entry;
// Assuming `toEmail` is a custom field on the entry.
Craft::$app->getMailer()->compose()
->setSubject('Thanks for your submission!')
->setTextBody('You are amazing.')
->setTo($entry->toEmail)
->send();
});
You can generate Craft 3 boilerplate plugin code using https://pluginfactory.io/ and the official Craft 3 Plugin docs are here: https://docs.craftcms.com/v3/extend/plugin-guide.html