O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending emails

We wanted to use our MailLogger to send out an email whenever we are logging an error. So let's go back to our class and add this logic.

This is what our log() method can look like:

  /**   * {@inheritdoc}   */  public function log($level, $message, array $context = array()) {    if ($level !== RfcLogLevel::ERROR) {      return;    }    $to = $this->configFactory->get('system.site')->get('mail');    $langode = $this->configFactory->get('system.site')->get('langcode');    $variables = $this->parser->parseMessagePlaceholders($message, $context);    $markup = new FormattableMarkup($message, $variables);    \Drupal::service('plugin.manager.mail')->mail('hello_world', 'hello_world_log', $to, $langode, ['message' => $markup]);  }

First of all, we stated that we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required