Answers.Body: <p>You should add it to custom-made module. </p>
  
  <p>Go to <a href="https://pluginfactory.io/" rel="nofollow noreferrer">https://pluginfactory.io/</a> to generate your module scaffolding (you don't need to select any additional components like models, variables etc for this), then install it accoding to instructions in readme file.</p>
  
  <p>After that, attach to event in module <code>init()</code> function:</p>
  
  <pre><code>    public function init()
      {
          parent::init();
          self::$instance = $this;
          Event::on(Mailer::class, Mailer::EVENT_AFTER_SEND, function(SendEvent $e) {
             // custom logic...
          });
      }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-17T09:59:05.163Z
Answers.LastActivityDate: 2019-06-17T09:59:05.163Z
Answers.UserDisplayName: Piotr Pogorzelski
Body: <p>I am using the contact form plugin in Craft CMS 3. I want to add the <code>afterSend</code> event. Where should I add the file to write the code for the <code>afterSend</code> event?</p>
  
Tags: <plugin-contactform>
Title: Where should I add the file to write the code for the `afterSend` event for contact form plugin?
ThreadText: # Where should I add the file to write the code for the `afterSend` event for contact form plugin?
  
  (Asked by: username_0 on 2019-06-17)
  
  I am using the contact form plugin in Craft CMS 3. I want to add the `afterSend` event. Where should I add the file to write the code for the `afterSend` event?
  
  **Tags:** plugin-contactform
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-17. Score: 1
  
  You should add it to custom-made module.
  
  Go to <https://pluginfactory.io/> to generate your module scaffolding (you don't need to select any additional components like models, variables etc for this), then install it accoding to instructions in readme file.
  
  After that, attach to event in module `init()` function:
  
  ```
      public function init()
      {
          parent::init();
          self::$instance = $this;
          Event::on(Mailer::class, Mailer::EVENT_AFTER_SEND, function(SendEvent $e) {
             // custom logic...
          });
      }
  
  ```
  
  
  ---
  
  