How can I include user pictures in e-mail notifications sent by the privatemsg module? 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?
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:

&lt;?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-&gt;author-&gt;uid);

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

  // Set up variables for our message body.
  $variables = array(
    'from' =&gt; $account_from-&gt;realname,
    'link' =&gt; l('Click here to view/reply to this message', $base_url . '/messages/view/' . $message-&gt;thread_id, array('external' =&gt; TRUE)),
    'message' =&gt; check_markup($message-&gt;body, $message-&gt;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-&gt;subject;
  $email_to = $account_to;
  $email_from = $account_from-&gt;realname . ' &lt;' . $account_from-&gt;mail . '&gt;';

  // Now, use whatever mechanism you want to send the actual email.
}
?&gt;