I'm using an Entity Reference field with select list, target type User

(so a user can be selected and saved as event organizer)

How can I fetch the actual email (instead of name) so i can use it in send mail as recipient?

I tried using [event-node:field-eventorganizer:uid] as the token but doesn't work. Also tried to add a Fetch by entity User in hope that could make the mail token available from that user field.

FYI-I checked the nodes fields and the user ID is definitely in the field

field_eventorganizer (Array, 1 element)
und (Array, 1 element)
0 (Array, 1 element)
target_id (String, 2 characters ) 43

I read tons of posts and tried many options but just couldn't figure it out, please help.

  • you have target id it's your uid so load the user like $user = user_load(field_eventorganizer['und'][0]['target_id']); and then you can get the mail field $mail = $user->mail->value – berramou Apr 30 at 16:08
  • add a condition, entity has field, your ER field, then another contition, entity has field, with your ER field, user email field, done. it could be more accurate my comment or ansewr if you explain better your event and whats fields yoy have. – pinueve Apr 30 at 16:42
  • @berramou thanks but i'm using rules for sendmail and need to be able within sendmail to use the mail field from the user field, thus can't use code. – Markus Apr 30 at 17:25
  • @pinueve oh wow you're the best, thanks for the quick and relevant answer, it would never occur to me that the relationship linkage has to be done as "condition" instead of an Action :) I only added the first condition which already worked via "registration:entity:field-eventorganizer:0:mail". Hence wondering if the second condition is needed at all? Actually I'm wondering how I can do it so accepts multiple users, as sendmail doesn't accept "registration:entity:field-eventorganizer:mail" FYI - I'm only using one ER User field (no email fields) – Markus Apr 30 at 17:38
  • Rules is a beauty, to do that you need lists and loops, you need to leran more, for D7 (many concepts apply to D8) see youtube.com/watch?v=QL1Rp69Lq80&list=PL84B6FFA4F7ACAD57 & drupalize.me/series/learning-rules-framework-series, good luck – pinueve Apr 30 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.