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 at 3:32
  • it is Guest Entries 2 for Craft 3 – Alex Ryhluk Aug 13 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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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