Created
June 23, 2016 14:03
-
-
Save peterlozano/016ec0bd7bbf49bcf9bc8b0749975bf1 to your computer and use it in GitHub Desktop.
Sending mail from drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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