Download & Extend

Send tokenized e-mail - token fields not populated

Project:Simplenews
Version:6.x-2.x-dev
Component:Usability
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I have the latest version installed and am trying to set-up the sending of a tokenized email when someone either subscribes or unsubscribes to a newsletter.

The email is being sent, but the token fields are coming through unpopulated - eg [simplenews-receiver-mail] is showing up as [simplenews-receiver-mail] in the email.

Global tokens appear ok in the email.

Am I trying to use the tokens for a use they weren't intended for?

Comments

#1

The tokens are supported only in the simplenews (un)subscribe confirmation emails. Not in other emails e.g. Sent by Actions or Rules. Are all simplenews tokens not replaced?

#2

oh, ok Sutharsan. Tokens are working fine in the simplenews (un)subscribe confirmation emails. I was trying to use them in actions.

A few of my client want an email sent to them any time a user (un)subscribes to their sites newsletters (including the email address of the (un)subscriber) and I was hoping I could do that with actions and tokens.

Could I modify the function to bcc a message to her when a user (un)subscribes? If so, what function should I be looking at, or is there another way I can achieve this?

Thanks.

#3

A small module with a hook_mail_alter implementation will do just that.

#4

Hello,

i followed your advice to use a hook_mail_alter approach.

/*
* Implementation of hook_mail_alter().
*/


function simplenews_action_mail_alter(&$message) {
if ($message['id'] == 'token_actions_action_send_email') { 
    // Add the newsletter info to the parameters and get the token values
    $message['params']['newsletter'] = $message['params']['object']->subscribed;
    $variables = simplenews_token_values('simplenews', $message['params']);
   
    // Update the email with the token values
    $subject = strtr($message['subject'], $variables);
    $body = strtr($message['body'][0], $variables);
    $message['subject'] = $subject;
    $message['body'][0] = $body;
 
  }
}

In this way i get almost all simplenews tokens working in mails sent with "actions", but i can't get [simplenews-receiver-mail] token for anonymous users.

I checked $account->mail , and is in fact empty

      $values['simplenews-receiver-mail']       = $account->mail;

I wonder if i can get the equivalent of %user prompted in drupal_set_message in the mails sent trough actions...

Is there any way to get the email address of the anonymous newsletter receiver?

Regards

Daniele

#5

Where do i put this code ?

nobody click here