It would be nice to include in a newsletter something like:

Hello, {profile_firstname}!

This would then pull from the proflie of each user their firstname and put it in for each personalized newsletter sent out.

Comments

sutharsan’s picture

Title: Support Profile Mail Merge Tokens » Support Token module
Version: 5.x-1.1 » 6.x-1.x-dev

This could be achieved with an integration of Token module with simplenews. Patches are welcome.

sutharsan’s picture

Duplicate request: #364408: Token integration

sutharsan’s picture

StatusFileSize
new1001 bytes

I had this half finished simplenews.token.inc module in my sandbox. Perhaps someone wants to take if further. Using the recently added function simplenews_mail_tokens() it should not be too hard.

TBarregren’s picture

I would also suggest that the Token module is used instead of the SImlenews specific tokens %site, %uri, %uri_brief, %mymail, %date, %login_uri.

sutharsan’s picture

I couldn't agree with you more.

sutharsan’s picture

sutharsan’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Changing version to HEAD. That's were the action is ;)

sutharsan’s picture

Status: Active » Needs work

Duplicated by #87071: Personalizing newsletters. Contains D5 patches.

Jean-Philippe Fleury’s picture

subscribing

kenorb’s picture

If somebody want quick custom variables, you can add your own function in:

function simplenews_mail_tokens($subscription, $context, $language) {
...
  if (function_exists('my_module_get_mail_tokens') ) {
    $vars = array_merge($vars,my_module_get_mail_tokens());
  }
       
  return $vars;
}

Then you can use your own function:

function my_module_get_mail_tokens() {
  global $user;    
    
  $tokens = array(
    '!user_name' => $user->name,
    '!something' => 'bla bla bla',
  );
    
  return $tokens;
haus’s picture

I am very interested in your solution for personalization of newsletters.
Could you tell where to put your functions and how to use them with simplenews, please.
Thanks

Pboenisch’s picture

Assigned: Unassigned » Pboenisch

Im new on Drupal.org but i am interested in changing the simplenews_mail_tokens into tokens from the token module like Sutharsan wrote in his third post.
In the next days i write how the development is going on.

eikes’s picture

StatusFileSize
new2.27 KB

Applying this patch allows you to use !recipient_name in your mail or template.

If the mail is sent out to an anonymous subscriber the email is inserted instead.

sutharsan’s picture

@Pboenisch: any progress on your development?

@Eikaa: this is perhaps a nice intermediate solution, but implementing Token module is not about adding an individual place holder. Token gives much, much more options that just recipent name.

Pboenisch’s picture

@Sutharsan: It is in work. I am still making the last tests with the tokens. At the moment it looks well and i think i can upload it in a few days

kenorb’s picture

You can use mail_alter hook for define some custom tokens:

Example:

/**
* Implementation of hook_mail_alter
*/
function mymodule_mail_alter(&$data)  {
    if (isset($data['params']))    {
        $var = array ('!my_custom_variable' => 'my variable data'); 
        $data['body']['body'] = strtr($data['body']['body'], $var); 
    }
}
IWasBornToWin’s picture

@Pboenisch I would love to test your new token code when you're finished.

kenorb’s picture

Simpler solution:

/**
 * Implementation of hook_mail_alter().
 *
 */
function hook_mail_alter(&$message) {
  /* detect mail body format */
  if (is_array($message['body'])) {
      $body = &$message['body']['body'];
  } else {
      $body = &$message['body'];
  }
  $body = token_replace_multiple($body); /* replace all available tokens */
}

Define this hook to replace all tokens available in body mail.
Eventually you can add some condition if Token module is enabled.

Jackinloadup’s picture

subscribing

Pboenisch’s picture

StatusFileSize
new19.2 KB

Hi there

i'm sorry that you must wait so long for this patch. I didn't had the time for this because i wrote my bachelor thesis.

Here is my patch for the simplenews 6.x-1.0-rc6. I removed the simplenews_mail_tokens function and added the well-known token_list and token_values functions.

Please test it and give me feedback.

johngriffin’s picture

I would love to test this out but it fails against current HEAD, can you re-roll please?

In the meantime I'll apply it to an earlier revision and check it out.

Thanks,
John

johngriffin’s picture

Patched the failed hunks manually and it all seems to be working. I'm also adding my own tokens to insert a content listing view based upon the user's profile preferences. Fantastic, thanks for this!

sutharsan’s picture

Status: Needs work » Needs review
StatusFileSize
new11.69 KB

This is a patch for current HEAD for those who also want to test and report their results.

sutharsan’s picture

StatusFileSize
new19.29 KB

I had a better look at Phoebisch's patch. It failed and I had to completely overhaul the code. A new patch (for HEAD) for review is attached.

kwinters’s picture

+dependencies[] = token

This is probably not needed... It should be fine to make it an "optional dependency" just like with mailmime.

I can't tell if it would work with this patch or not, but I'm definitely going to need access to $user->profile_company, etc. (ability to pull in user profile fields and map them to a token usable in the send, even if it requires a hook in a custom module).

Nothing else jumps out at me, I'll have to see how it works in practice.

sutharsan’s picture

Assigned: Pboenisch » Unassigned

Tokens are also used for the confirmation emails. This makes token a requirement. To use this part without tokens would mean that simplenews requires two systems of token replacement. Token is used in 50% of the drupal 6 installations and is the third most used module. I don't see a real problem in making simplenews dependent on token.

miro_dietiker’s picture

StatusFileSize
new21.78 KB

I've checked the patch and found two issues:
1. All tokens where displayed in admin for mail replacement. Added token_help specifier. I home this is correct behaviour.
2. Footer .tpl.php tokenized update was missing.
3. Removed unused obsolete email_token_help in .admin

Everything else unchanged.

In general i think it works pretty well, although i've found a bunch of small errors to fix outside of the scope of this issue.

sutharsan’s picture

Thanks for your review. I leave the issue open for a little longer to get another review but for me the last patch is already RTBC worthy.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Setting to RTBC. Checked another couple of minutes and reproducing code and especially checking static caching not to cache things that shouldn't be cached...

Seems perfectly right. Cool patch, Sutharsan!

Next step in evolution is:
#581500: Conditional personalisation and dynamic (uncacheable) filters

miro_dietiker’s picture

We need a note for users who upgrade to make clear they need to rewrite their mailings.
If not they will result having broken obsolete replacement patterns inside mails.

sutharsan’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new23.63 KB

I've added a replace function for the confirmation messages and a user message.

Attached patch is committed to HEAD. Thanks to all for encouragement, code and test.

miro_dietiker’s picture

Very nice! Thanks a lot.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gantenx’s picture

StatusFileSize
new1.33 KB

Hi, I have created simplenews_token module to integrate simplenews and token module. I developed it for drupal 6. What do you think?

sutharsan’s picture

I'd rather combine efforts for this function. Please check-out simplenews HEAD, review and supply patches for it.

chinaKat’s picture

Hi -- thanks for the module. Call me a newbie loser but I haven't quite nailed patch installation, so I was struggling with this. Having a module was great, I could use it right away. But, I don't know if it does what I need.

Problem: I used the global tokens listed at /admin/store/help/tokens in my newsletter, and they mostly worked great. However, the [user-name] token gives the name of the currently logged in user, which is no help to me in a newsletter because all the newsletters wind up being addressed to "admin" or "bob" or whoever creates the newsletter.

Is there a token available to get the user name of the user receiving the email?

Thanks!

ETA --

aha, I see that there is a drop down menu in the newsletter edit screen titled "replacement patterns" with the user tokens. [user] works perfectly.

Thank you for making this available, I appreciate it!

UNarmed’s picture

Just installed the module, realy hope it done the trick =] thanks!

roball’s picture

Status: Closed (fixed) » Active

The module posted at #35 is not needed with simplenews 6.x-2.x-dev (thanks for contributing, gantenx anyway!) since it has token support in core. Some could use

"Dear [simplenews-receiver-name]"

on top of the body. This resolves into the username of the recipient if she is registered on the site. If not (anonymous subscription), the sent mail will read

"Dear Anonymous"

which is not really useful. If a subsriber is anonymous, [simplenews-receiver-name] should resolve into a configurable string (something like "subscriber"). How could this be done?

sutharsan’s picture

Status: Active » Closed (fixed)

Roball, Token does not support conditional token replacement. You need to write a module for this or give 'anonymous' a new name (site wide).

roball’s picture

So I have created the issue #660496: Setting [simplenews-receiver-name] token's value for anonymous subscriber for trying to find a solution for that.

dsms’s picture

subscribe

ShadowMonster’s picture

subscribe

Matthi2’s picture

Thank you very much!
It works fine with the username!