I have a task content type. One of the fields is an "Assigned To" field. This field is a user reference and more than one user can be referenced. I set up rules to send an e-mail to the referenced users. It only sends the e-mail to the first referenced user. How can I get it to send the e-mail to all the referenced users chosen?
Comments
Comment #1
epop commentedComment #2
crizHi, only one referenced user gets loaded I guess, don't know if loading multiple referenced user would be a good idea and would help you very much..
But you can use a simple php snippet like the following. Just adapt it and copy it in the recipient field (Has to be short, so code is not the prettiest. Not tested.):
Make sure that $node->field_userreference has a value (condition).
Comment #3
epop commentedI reference multiple user-fields so that more than one user can be assigned to a task. And I wanted all assigned users to be notified.
Comment #4
uniquename commentedHi,
I have the same problem and can not see wich recipients filed the code in #2 should go. "Send a mail to an arbitrary mail address" action does not accept php code in the reciepients field.
Comment #5
rich.yumul commentedsubscribing....
Comment #6
niklp commentedSubscribing
Comment #7
mayerwin commentedsubscribing
Comment #8
niklp commentedI have a fix for this in as much as I can get emails sent to multiple users in a user reference field...
However, it depends on this issue being fixed: #375337: userreference relationship for views with base 'user'
If that issue can be resolved, the relationship is then available for all user reference fields, and the email problem can be solved using a combination of VBO/Views/Rules.
Comment #9
zeezhao commentedsubscribing.
Comment #10
ozecho commentedThe snippet of code in #2 (modified with my userfield) worked for me in the recipient field of the send an email to an arbitrary address.
Thanks a bunch @criz.
Comment #11
stephenhendry commented@ozecho & @criz do you need to do anything else? I get the following error:
"Unable to send e-mail. Please contact the site administrator if the problem persists."
Looking into the logs I have the following:
Error sending e-mail (from no-reply@domain.com to
foreach ($node->field_notify as $r) {$u = user_load($r['uid']); $m[] = $u->mail;} echo implode(',', $m);).Comment #12
niklp commentedFYI the patch at http://drupal.org/node/375337 is tested and working now so you should be able to use the rule/vbo/rule set method to email users using events and user ref fields no problem.
I have this set up, tested and working. Need to document it really...
Comment #13
criz@gazelle
make sure that PHP code can be evaluated. PHP filter module activated?
But have a look at #12, seems to be a good solution!
Comment #14
milant commentedGreat! The snippet in #2 solved by problem. Thanks for that criz!
MT
Comment #15
jwilson3Thanks! #2 solved my problems... If you want more flexibility, instead of adding the PHP directly in the Send email to an arbitrary user Action's recipient field, you can Add an action "Rules: Add a new string variable", and paste the php in #2 into the String field, and provide a machine readable variable name (something like 'recipients'). Finally you can use the token that is created in the 'send email' action, or show a message to the screen, for testing purposes.
Comment #16
milant commentedSo I was using the snippet in #2 (successfully) for the last month. Now, when I submit my form (with no user references) it has an error "Unable to send e-mail. Please contact the site administrator if the problem persists." I know how to fix the php to make this stop but the recipient field is set to a max of 128 characters. I only need about 10 more than that. Just recently, it was not showing an error if this field was left blank.
I'm curious if anyone else is getting this error now. And if anyone knows how to increase the recipient field in the "send a mail to an arbitrary address" action? This error is getting quite frustrating since it has only been doing this as of lately.
Thanks!
Comment #17
criz@Milant
Have a look at #15, this is a better solution anyway.
Comment #18
milant commentedHello criz,
I tried that before. But the problem is fitting the php code snippet i am using in the field for that variable (still 128 char max). However, i did create the snippet in a smaller version. And just added ",0" to the end. Therefore, if it is empty, it thinks it sends an email to the address "0" which it obviously doesn't, but the warning is gone. A little sloppy, but does the trick.
Thanks.
Comment #19
jwilson3MilanT is correct, my solution in #15 suffers from the same character limitations as the original solution. The only difference is you can use the resulting string of emails as a token for various actions, instead of just the email.
The 128 char limit sucks a lot on those core rules actions: 'add a new string/integer/float/ etc variable' prolly needs a separate ticket.
I guess it could be argued though that if you need more characters, you're better off writing a function in code somewhere, and calling it in the from the text box, passing in the appropriate/available objects (in this case the $node object).
Comment #20
thadwheeler commentedNikLP, can you expand on how you accomplished this with VBO/Views/Rules?
Comment #21
criz@thadwheeler
have a look at http://nodeone.se/blogg/nodeone-talks-drupal-rules-vbo-revisited and http://drupal.org/project/rules_views maybe this is helping...
Comment #22
thadwheeler commented@criz thank you, I will take a look at these.
Comment #23
jwilson3Figured I would solve the problem found in #18, expanding upon the idea mentioned in #19.
The basic premis, is to replace the long string of php code proposed in #3 with a short function call in the recipient field.
My function, in a custom module, looks like this:
I then put the following shorter snippet into the recipient field in the rule definition's "send a message" action:
<?php print _ami_programs_program_author_emails($node); ?>I believe with this information we now have two to three ways to solve this issue, and it looks like there are other issues that seek to add similar functionality via VBO, so I'm marking this one resolved. Feel free to reopen if you want to contribute better solutions.
Comment #24
Exploratus commented#23 worked great for me!!!!
I feel that this should be built into the module.
Comment #25
hanching commentedI have to put "php" copy to where ...?
How to use PHP CODE you mentioned that place to place, to make reference field, read Mutiple value it ...
Comment #26
jwilson3@hanching:
Please be more specific: which of the two solutions above that mention php code are you trying to implement?
Comment #27
marcelomg commentedHi I'm trying the #2 option but it's not working for me.
I'm using a CCK user reference field. I have evaluated the PHP code and it returns all the emails. My PHP Filter Module is enabled.
I'm using Send a mail to an arbitrary mail address. If I enter just one User on the field that I'm using as a reference it works, but with more than one it doesn't send any emails. So the code seems to be working but somehow the second User Reference is messing it up.
I would appreciate any help,
thanks
Comment #28
ressaThanks @jwilson3 (post #15), using "Rules: Add a new string variable" I can now fit in an email to admin in the Recipient field :-)
Note to others: Remember that the "Add a new string variable" action has to be executed before the "Send a mail to an arbitrary mail address" action, otherwise the token won't be available. You can use the devel module to see if it works, just select "Log only" under "Devel settings" -> "SMTP library".
Comment #29
eidoscomI did a component for rules that extract e-mails from a user list. You must provide a user list to the component, and the component returns a comma separated list of emails ready to print directly to a CC, BCC or recipient for sending an email.
Hope that this can help someone!
Comment #30
trailrunner commented#29 is an excellent solution. Thank you so much!