Skip to content

Instantly share code, notes, and snippets.

@peterlozano
Created June 23, 2016 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterlozano/016ec0bd7bbf49bcf9bc8b0749975bf1 to your computer and use it in GitHub Desktop.
Save peterlozano/016ec0bd7bbf49bcf9bc8b0749975bf1 to your computer and use it in GitHub Desktop.
Sending mail from drupal 8
<?php
// To be passed to hook_mail
$params = array();
// To be passed to hook_mail
$key = 'my_mail_key';
$langcode = \Drupal::languageManager()->getDefaultLanguage();
\Drupal::service('plugin.manager.mail')
->mail('module_name', $key, $to, $langcode, $params);
<?php
/**
* Implements hook_mail().
*/
function module_name_mail($key, &$message, $params) {
switch ($key) {
case 'my_mail_key':
$message['subject'] = 'New mail for you';
$message['body'][] = 'Message body';
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment