October 2017
Intermediate to advanced
566 pages
14h 31m
English
As I mentioned earlier, the first step for sending mails in Drupal 8 is implementing hook_mail(). In our case, it can look something like this:
/** * Implements hook_mail(). */function hello_world_mail($key, &$message, $params) { switch ($key) { case 'hello_world_log': $message['from'] = \Drupal::config('system.site')->get('mail'); $message['subject'] = t('There is an error on your website'); $message['body'][] = $params['message']; break; }}
This hook receives three parameters--the message key (template) that is used to send the mail, the message of the email that needs to be filled in, and an array of parameters passed from the client code. As you can see, we are defining a key (or template) named hello_world_log ...
Read now
Unlock full access