1

I have the Private Message module configured to send notifications when users receive a private message. I have the Mime Mail module configured and working; the private messages are sent as HTML and display properly. However, I have been unable to find a way to include user pictures in the messages.

On my site, I have a field that contains the user picture (I am not using the standard user pictures built-in to Drupal). However, I have overridden the user pictures template to show this field, so a solution that works for user pictures should hopefully work for my case as well.

I tried to solve this with tokens.

The token module makes available the following token: [privatemsg_message:author:field_acc_profile_picture]

However, when I include this token in the message, it is simply returned as a text string; no substitution is performed.

I thought this could be done with PHP but there is no way as far as I can tell to include PHP in the e-mail notify message field.

So, how can I include user pictures in e-mail notifications sent by the privatemsg module?

1 Answer 1

2
+100

One way you could do this (which is what I do on a couple sites), is to implement hook_privatemsg_message_insert() in a custom module. Turn off the privatemsg module emails or any rules-generated emails, and instead write a custom bit of code that sends the private message.

In my case, I needed to do a few other customizations, but at its simplest, you can get a profile picture URL by loading the user $account from $message->author->uid.

A quick example:

<?php
/**
 * Implements hook_privatemsg_message_insert().
 */
function custom_privatemsg_message_insert($message) {
  global $base_url;

  // Get the account from which message was sent.
  $account_from = user_load($message->author->uid);

  // Get the person to whom the message is being sent (I only handle one).
  foreach ($message->recipients as $key => $recipient) {
    $account_to = $recipient;
    continue;
  }

  // Set up variables for our message body.
  $variables = array(
    'from' => $account_from->realname,
    'link' => l('Click here to view/reply to this message', $base_url . '/messages/view/' . $message->thread_id, array('external' => TRUE)),
    'message' => check_markup($message->body, $message->format),
  );

  // Print the message body using a custom theme function. Because email clients
  // require obnoxious markup, it's best to use a theme function or template...
  $body = theme('custom_private_message', $variables);
  $body_plain = strip_tags($body);

  $subject = t('New Private Message: ') . $message->subject;
  $email_to = $account_to;
  $email_from = $account_from->realname . ' <' . $account_from->mail . '>';

  // Now, use whatever mechanism you want to send the actual email.
}
?>
0

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .