hook_mail

  1. drupal
    1. drupal6 core.php
    2. drupal7
Versionen
drupal6 – drupal7 hook_mail($key, &$message, $params)

Prepare a message based on parameters.

Übergabeparameter

$key An identifier of the mail.

$message An array to be filled in. Keys in this array include:

  • 'mail_id': An id to identify the mail sent. Look into the module source codes for possible mail_id values.
  • 'to': The mail address or addresses where the message will be send to. The formatting of this string must comply with RFC 2822.
  • 'subject': Subject of the e-mail to be sent. This must not contain any newline characters, or the mail may not be sent properly. Empty string when the hook is invoked.
  • 'body': An array of lines containing the message to be sent. Drupal will format the correct line endings for you. Empty array when the hook is invoked.
  • 'from': The From, Reply-To, Return-Path and Error-To headers in $headers are already set to this value (if given).
  • 'headers': Associative array containing the headers to add. This is typically used to add extra headers (From, Cc, and Bcc).

$params An arbitrary array of parameters set by the caller to drupal_mail.

See also

drupal_mail for more.

Verwandte Themen

Code

modules/system/system.api.php, line 879

<?php
function hook_mail($key, &$message, $params) {
  $account = $params['account'];
  $context = $params['context'];
  $variables = array(
    '%site_name' => variable_get('site_name', 'Drupal'),
    '%username' => $account->name,
  );
  if ($context['hook'] == 'taxonomy') {
    $object = $params['object'];
    $vocabulary = taxonomy_vocabulary_load($object->vid);
    $variables += array(
      '%term_name' => $object->name,
      '%term_description' => $object->description,
      '%term_id' => $object->tid,
      '%vocabulary_name' => $vocabulary->name,
      '%vocabulary_description' => $vocabulary->description,
      '%vocabulary_id' => $vocabulary->vid,
    );
  }

  // Node-based variable translation is only available if we have a node.
  if (isset($params['node'])) {
    $node = $params['node'];
    $variables += array(
      '%uid' => $node->uid,
      '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
      '%node_type' => node_get_types('name', $node),
      '%title' => $node->title,
      '%teaser' => $node->teaser,
      '%body' => $node->body,
    );
  }
  $subject = strtr($context['subject'], $variables);
  $body = strtr($context['message'], $variables);
  $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
  $message['body'][] = drupal_html_to_text($body);
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen