Sending form to mail from custom module fails without error I've created a module with a form and a block.
When I push the subscribe button, the submitForm function is executed.
The successmessage is shown, but no e-mail is send ...
There are no errors reported in the recent logmessages or in on the server in the folder /logs.
public function submitForm(array &amp;$form, FormStateInterface $form_state)
    {
        /**
         * @var MailManager $mailer
         */
        $mailer = \Drupal::service('plugin.manager.mail');

        $email = $form_state-&gt;getValue('email');
        $params['context']['subject'] = &quot;Subscribe newsletter&quot;;
        $params['context']['message'] = 'Someone subscribed: ' . $email;
        $params['email'] = $email;

        try {
            $response = $mailer-&gt;mail('my_module', 'subscribe', 'to@email.com', 'nl', $params);
            if ($response) {
                $this-&gt;messenger()-&gt;addStatus($this-&gt;t('You are successfully subscribed to our newsletter with your e-mail: @email', ['@email' =&gt; $email]));
            } else {
                $this-&gt;messenger()-&gt;addStatus($this-&gt;t('There was an error.'));
            }
        } catch (MailHandlerException $e) {
            \Drupal::logger('mailinglist_send_mail_error')-&gt;notice('&lt;pre&gt;&lt;code&gt;' . print_r($e, true) . '&lt;/code&gt;&lt;/pre&gt;');
        }

    }
Did you implement hook_mail in your module? – Alfred Armstrong
where to place the hook_mail function? – Lance

Goes in the .module file. Ex: my_module.module
/*
* Implements hook_mail().
*/
function my_module_mail($key, &amp;$message, $params) {
  switch($key) {     
    case 'my_module':
      $options = [
        'langcode' =&gt; $message['langcode'],
      ];
      $message['subject'] = t('@title', ['@title' =&gt; $params['context']['subject']], $options);
      $message['body'][] = t('@body', ['@body' =&gt; $params['context']['message']], $options);         
      break; 
  }
}

Flush all caches so hook gets picked up.