-1

Drupal mail is sending messages to

username <email@domain>

This looks like martin-green

I would like to specify the user name as "Martin Green ".

We have extended the user fields to include first and last names.

The email messages are constructed as follows:

  $result = drupal_mail(YogaHivePasses::MODULE_NAME, self::EMAIL_KEY, $userFromOrder->mail, $lang, $message);

There is a hook_mail

function yhivepasses_mail($key, &$message, $params) {
  switch ($key) {
  case YogaHivePasses::EMAIL_KEY :
    $message['subject'] = $params['subject'];
    $message['body'] = $params['body'];

    // May not be any parameters. Parameters are mainly used to send attachments.
    if (array_key_exists('params', $params)) {
    $message['params'] = $params['params'];
  }

  foreach ($params['headers'] as $key => $value) {
    $message['headers'][$key] = $value;
  }
  break;
default:
  return;
 }
}

The mimemail module is installed.

0

You can format email sender right before calling drupal_mail()

  $name = 'Martin Green';
  $mail = 'email@domain.com';

  $from = '"' . addslashes($name) . '" <' . $mail . '>';

  $result = drupal_mail(YogaHivePasses::MODULE_NAME, self::EMAIL_KEY, $userFromOrder->mail, $lang, $message, $from);

or in hook_mail()

function yhivepasses_mail($key, &$message, $params) {
  switch ($key) {
    case YogaHivePasses::EMAIL_KEY :
      // You can pass these variables to drupal_mail() or get them somehow.
      $name = 'Martin Green';
      $mail = 'email@domain.com';

      $message['from'] = '"' . addslashes($name) . '" <' . $mail . '>';

      $message['subject'] = $params['subject'];
      $message['body'] = $params['body'];

      // May not be any parameters.
      // Parameters are mainly used to send attachments.
      if (array_key_exists('params', $params)) {
        $message['params'] = $params['params'];
      }

      foreach ($params['headers'] as $key => $value) {
        $message['headers'][$key] = $value;
      }

      break;

    default:
      return;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.