Hello,

I have not found any answer to the following issue.
I am using Rules to send emails "after updating an existing content".
For any field of the "Send mail" action, if I am using the "Data Selection" mode, the token that I choose comes out fine in the email sent ([node:title] is replaced by the title of the node).

However, I need to add some extra text to my Message body, so I switch to "Direct input" mode. And here:
- no token shows under replacement patterns section.
- when I put any token such as [node:title] or [node:field-date:value], it returns a blank space in the email instead of the value it stands for.

Another issue which seems related, the PHP evaluation option does not show either when either on "Direct input" or "Data Selection" mode.

Config:
Rules, Rules UI (All 7.x-2.9)
Workflow Rules 7.x-2.5

Entity tokens, Token 7.x-1.5
Token tweaks 7.x-1.x-dev

HTML Mail 7.x-2.65
Mail System 7.x-2.34

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Back From 7’s picture

Component: Rules Core » Rules Engine

CONFIRMED: 'send an email' action with the following modules.

Entity 7.x-1.x-dev
Rules 7.x-2.x-dev
Token 7.x-1.x-dev

[node:url] token replacement works and shows up in email.

Back From 7’s picture

'Send mail to all users of a role' DOES NOT WORK. Used the same configuration as 'send email' THIS IS A MAJOR PROBLEM...

Back From 7’s picture

SOLUTION: It seems like Mime Mail module did the trick. It allows for html mail system. Maintainers need to mention this in "required modules". I would think email rules are widely used...

marty.true’s picture

I have Mime Mail installed and it still will not send emails when using a token in the body of the message. I am not using "Send as HTML". Confirmed, when removing the token, the emails go through...

greenitcompany’s picture

I'm also experiencing this issue. Has anyone identified a solution?

ezeedub’s picture

Title: RULES AND TOKEN = NO EMAIL SENT » token replacement not working?
Priority: Major » Normal
Issue tags: -issues, -replacement, -drupal 7 +token replacement

Seems to me this problem is about token replacement and not email, if the email works without tokens.

I encountered the error last night, but today haven't been able to re-create it. :/

Anyway, for me it was related to not being able to get at [entity:nid], without first loading it. So, in my actions, I first "fetch entity by id" using entity:nid as a data selector, and then when I want the token, I use [entity-fetched:nid].

I don't understand why this works though.

Back From 7’s picture

@xstatic

Make sure to configure Mimemail to be used system wide. There is a configuration under Mimemail settings I think. You have to tell Drupal to use Mimemail html mail site wide.

Hope this helps!

nlisgo’s picture

I am getting the same error if I set up an action to 'Show a message on the site' and use the data selector and refer to any of the variables like site:mail for instance. It will save but when I return to edit the action that message is displayed.

raphpaelle’s picture

Hi,

I've got the same problem, token replacement doesn't work when using token such as node:author or node:author:mail. It's really blocking.
Is there any way to solve this problem please?

larowlan’s picture

Component: Rules Engine » Rules Core
Status: Active » Needs review
FileSize
1.25 KB

This works for me.
Seems to be when the data type 'entity' is involved. For which there are no tokens.
This tests for that and drops back to the raw entity and entity_type.

thememex’s picture

Issue summary: View changes

@larowlan

Thank you for posting this patch. I've been banging my head against a wall for weeks trying to get a Rule to set a text field value to a Token. That Token is an 'entity' type containing arrays. Example: [entity:field-date-repeat:0:duration]

I had built the rule to look for entities with entity:field-date-repeat, and even set a condition to check if the entity:field-date-repeat:0:duration had a value. All the rule would ever do is populate the field and set a blank value. I could add text or PHP or site tokens (ie - [site:name]) and all of those would populate my text field. I just could not pull in the array value from an entity token.

Simply applying your patch to Rules (I'm on version 7.x-2.9) instantly fixed this problem for me with no changes to my existing rule.

Thank you. Thank you. Thank you.

eawheeler’s picture

I can confirm that the patch per # 10 solved my problem. My rule sends an email message on node update. Prior to patch application, the message body field would not populate [entity:url] tokens and rule triggering would result in the following UI error.

Undefined index: entity_type in uuid_tokens() (line 51 of /var/www/html/profiles/panopoly/modules/contrib/uuid/uuid.tokens.inc).

I had attempted another approach that fetched entity by id. That worked up to a point and resolved the token population issue. However it also resulted in PDOExceptions.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

The PDO error possibly occurred because I had applied more than one rule to the content type that retrieved IDs in this fashion. In any case, after patch application I was able to rework the rule to use [entity:*] tokens and removed the "fetch entity by id" actions.

eawheeler’s picture

Status: Needs review » Reviewed & tested by the community
Göran’s picture

Issue summary: View changes

THANK YOU!
This Patch solved a major problem ho did come up, after the core (dp7.38 from 7.37) and some module was updated. I hade a Rule who find value from fields inside a book-ancestor-2:

[node:book-ancestors:2:title] - Who was blank 
AND this content type field couldn't be find (from another content type, for the "parent" book-level) :
[node:book-ancestors:2:field-race-shortname] 

After this patch update - Rules is able to find the values and the missing fields value.

Thanks a lot for this patch i it rescued my day, or probably the hole week...!

Göran’s picture

Issue summary: View changes
crutch’s picture

Very odd. Tokens were not working in email message field, plain text. Applied patch #10. Tokens started working. Reverted to original system.eval.inc file, tokens are still working.

rlmumford’s picture

Title: token replacement not working? » Token replacements don't work on parameters with type "entity"
Category: Support request » Bug report

Patch is still good on latest dev. Can this get committed?

museumboy’s picture

I'm having a similar problem, but I can't get anything to work even after I applied the patch. Here's the code in my email rule:

$original = '[entity:field-info-request-1]';
$req1 =  token_replace($original);
print gettype($req1) . "\n";
print $req1) . "\n";

if ($req1 == "true") {
  print "<li>Relevant experience or courses that you may have had in your area of interest.</li> ";
} else {
print "the value of the var is ". $req1 ;
}

If info-request-1 is checked I get an email saying: string true the value of the var is true.
if info-request-1 i NOT checked I get an email saying: string false the value of the var is false.

Additionally, when the rule is run I see the same "warning: Undefined index: entity_type in uuid_tokens()” others have mentioned.

Why isn't my logic working?

rlmumford’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.39 KB

The patch in #10 breaks tokens in entities where the entity type differs from the token type (Commerce Order being one example). This updated patch solves the bug while maintaining the existing functionality.

To test import the following rules component and execute:

{ "rules_test_order_tokens" : {
    "LABEL" : "Test Order Tokens",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "entity" : { "label" : "Entity", "type" : "entity" } },
    "ACTION SET" : [
      { "drupal_message" : { "message" : "The user name is: [entity:name]" } }
    ]
  }
}

With Patch: The user name token will be correctly replaced
Without Patch: The user name token will be replaced blank.

nvahalik’s picture

+1 to the patch in #19.

TR’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Issue tags: -token, -rules, -token replacement
TR’s picture

It seems to me that this is the same as the problem being discussed in #2420687: Add token support for "any entity" data type.

I like the patch in that issue better.

Can someone look at both issues, figure out what needs to be fixed, and consolidate the two?

TR’s picture

Status: Needs review » Closed (duplicate)