You are here

mimemail_example.module in Mime Mail 8

Same filename and directory in other branches
  1. 7 modules/mimemail_example/mimemail_example.module

Hook implementations for the Mime Mail Example module.

File

modules/mimemail_example/mimemail_example.module
View source
<?php

/**
 * @file
 * Hook implementations for the Mime Mail Example module.
 */

/**
 * Implements hook_theme().
 */
function mimemail_example_theme() {
  return [
    // Normally, templates are only found when they are put into a theme
    // directory. This demonstrates how to provide a template with a custom
    // module, by providing a new theme hook that will be used when sending
    // mail from this module.
    //
    // The template use for this email is found in
    // templates/mimemail-message--mimemail-example.html.twig.
    'mimemail_message__mimemail_example' => [
      'render element' => 'elements',
      'base hook' => 'mimemail_message',
    ],
  ];
}

/**
 * Implements hook_mail().
 */
function mimemail_example_mail($key, &$message, $params) {

  // The $params array holds the values entered on the ExampleForm, stored
  // with the same structure as the $form array. We need to copy these values
  // to the appropriate place in the $message so that they get used when
  // sending the email.
  $message['from'] = isset($params['headers']['From']) ? $params['headers']['From'] : NULL;

  // Strip newline characters from e-mail subjects.
  $message['subject'] = isset($params['subject']) ? str_replace([
    "\r\n",
    "\r",
    "\n",
  ], ' ', $params['subject']) : NULL;
  $message['body'][] = $params['body'];
}

Functions

Namesort descending Description
mimemail_example_mail Implements hook_mail().
mimemail_example_theme Implements hook_theme().