Answers.Body: <p>This will only register your message with Craft. To then send it you would do something like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>Event::on(
      Elements::class, 
      Elements::EVENT_AFTER_SAVE_ELEMENT,
      function(Event $event) {
          if ($event-&gt;element instanceof \craft\elements\User) {
              $user = $event-&gt;element;
              if($event-&gt;isNew) {
                  Craft::$app
                      -&gt;getMailer()
                      -&gt;composeFromKey('after_activate_user')
                      -&gt;setTo($user)
                      -&gt;send();
              }
          }
      }
  );
  </code></pre>
  
  <p>This will listen for the <code>EVENT_AFTER_SAVE_ELEMENT</code> event, make sure it's a <code>User</code> being saved, check that it's a new user then send the message.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-22T16:15:50.020Z
Answers.Text: Where should this be setup? 
  New to craft here and looking for something similar to functions.php like in wp :)
Answers.UserDisplayName: Mario Sanchez Maselli
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-07T07:20:31.323Z
Answers.LastActivityDate: 2019-06-07T07:20:31.323Z
Answers.UserDisplayName: Oli
Body: <p>I want to send a welcome email to the user when they sign up (not an activation email). </p>
  
  <p>I can see the email and edit its text in the Control Panel, but the email doesn't send when a new user registers. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>Event::on(SystemMessages::class, SystemMessages::EVENT_REGISTER_MESSAGES, function(RegisterEmailMessagesEvent $event) {
      $event-&gt;messages[] = [
          'key' =&gt; 'after_activate_user',
          'heading' =&gt; 'When someone registers:',
          'subject' =&gt; 'Subject',
          'body' =&gt; 'Message text',
      ];
  });
  </code></pre>
  
  <p>My question, is there anything else I need to do to get this email to send? Do I need to define a recipient?</p>
  
Tags: <emails>
Title: How to register a new System Message email
ThreadText: # How to register a new System Message email
  
  (Asked by: username_0 on 2019-06-07)
  
  I want to send a welcome email to the user when they sign up (not an activation email).
  
  I can see the email and edit its text in the Control Panel, but the email doesn't send when a new user registers.
  
  Here is my code:
  
  ```
  Event::on(SystemMessages::class, SystemMessages::EVENT_REGISTER_MESSAGES, function(RegisterEmailMessagesEvent $event) {
      $event->messages[] = [
          'key' => 'after_activate_user',
          'heading' => 'When someone registers:',
          'subject' => 'Subject',
          'body' => 'Message text',
      ];
  });
  
  ```
  
  My question, is there anything else I need to do to get this email to send? Do I need to define a recipient?
  
  **Tags:** emails
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-07. Score: 2
  
  This will only register your message with Craft. To then send it you would do something like this:
  
  ```php
  Event::on(
      Elements::class, 
      Elements::EVENT_AFTER_SAVE_ELEMENT,
      function(Event $event) {
          if ($event->element instanceof \craft\elements\User) {
              $user = $event->element;
              if($event->isNew) {
                  Craft::$app
                      ->getMailer()
                      ->composeFromKey('after_activate_user')
                      ->setTo($user)
                      ->send();
              }
          }
      }
  );
  
  ```
  
  This will listen for the `EVENT_AFTER_SAVE_ELEMENT` event, make sure it's a `User` being saved, check that it's a new user then send the message.
  
  > **Comments:**
  > **username_2**: Where should this be setup?  New to craft here and looking for something similar to functions.php like in wp :)  
  
  ---
  
  