I am getting an error when using Rules:

Undefined index in rules_action_mail() (line 90 of mywebsite/sites/all/modules/rules/modules/system.eval.inc

The email is getting sent successfully, but this error keeps appearing as well. Any ideas on how to fix this?

CommentFileSizeAuthor
#10 rules_mail_lang.patch717 bytesfago
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

philipz’s picture

I have the same problem.

I'm running Drupal Commerce and on the checkout->completion I get that error and what's worse it makes confirmation page load for more than a minute. I'm not sure if the problem is related to this slow performance but disabling the rule sending the confirmation email makes it work super fast again.

EDIT:
In my case the rule was configured improperly. I probably intalled it without locale module enabled, and then after enablig it the rule required langugage and somehow data selector for it was set to order status.

zdean’s picture

I can confirm the error. My rule is set to send an email upon creation of a node. When a node is created, I get the error but the email is sent out as expected.

johnhoule’s picture

I'm also having this issue.

Event: After saving new content
Condition: Content is sticky
Actions: Unpublish content, Send mail, Show message on site

The email does go through but the page displays the error described above.

rtvWebServicesLibrarian’s picture

I can confirm this error as well. I have created a content type called "Event" that adds events to a site calendar.
When a new Event is created, the rule is supposed to allow the user to add one or more email addresses to send the Event information to.
Here is how my rule is constructed:

Event: after saving new content

Condition: entity has field: Parameter: Entity: [node], Field: field_email_notify
AND
Data comparison: Parameter: Data to compare: [node:field-email-notify], Data value:

Actions: Send mail: Parameter: To: [node:field-email-notify], Subject: You are invited to: "..., Message: You are cordially invited..., From: [site:current-user:mail], Language: [node:type]

Hope this helps!

philipz’s picture

I guess the Language should be set to node language or manually selected language not the node:type.

gagoo’s picture

I have the same problem. thanks

iancm’s picture

I'm currently experiencing this issue as well.

grensman’s picture

Same problem here, anybody have an idea on this or how can i hide the error message until this is solved?

lily.yan’s picture

I have the same problem. thanks

fago’s picture

Status: Active » Needs review
FileSize
717 bytes

Does this patch help you?

Status: Needs review » Needs work

The last submitted patch, rules_mail_lang.patch, failed testing.

fago’s picture

Status: Needs work » Needs review
luchoh’s picture

Title: Undefined index in rules_action_mail() (line 90 » Rebuild the mail rules
function rules_action_mail($to, $subject, $message, $from = NULL, $langcode, $settings, RulesState $state, RulesPlugin $element)

is changed from 2.0 to 2.1 - the fifth argument - $langcode is new.

I managed to get rid of the error message at line 90 by opening all my mail-related rules, editing the send mail action and removing the content of the Language field. It had an irrelevant value in it anyway.

I hope this helps.

lily.yan’s picture

Thanks a lot, it works for me by removing the content of the Language field.

rtvWebServicesLibrarian’s picture

I deleted and restored my site from an older backup, created the rule using slightly different logic, and the problem went away -- weird. Thanks so much for being out there to help!

luisasasi’s picture

I've seen the same problem after updating to 7.23 Dates. module.
I had to revise some rules.
Example
Edit condition: Data compare
before I had node: field-to-start-pub is less than today
now I have to write node: field-to-start-pub: value is less than today
Now everything is OK
Date.module is the problem

fago’s picture

Title: Rebuild the mail rules » Undefined index in rules_action_mail()

Please test the patch from #10 so we know whether it fixes the problem without requiring workarounds.

loze’s picture

#10 worked for me.

waverate’s picture

#10 works for me.

cedewey’s picture

Status: Needs review » Reviewed & tested by the community

#10 worked for me as well.

Everett Zufelt’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure if it is related, but I would be surprised if it were not. Since upgrading to Rules 7.x-2.1 our mail actions (executed on Drupal Commerce Checkout Completion) are set to the data selector commerce-order:state. The rules are in their default state, and the data selector is not featurized.

dotist’s picture

I was having the same problem - removing the language value fixed it for me (was not pertinent anyway).

Everett Zufelt’s picture

@dotist

Agreed, saving the send mail action after removing the content from Language and re-featurizing solves the problem. Is this related to the current issu, if so should it be rolled into the same patch?

FranckV’s picture

Here is the quick fix that worked for me:

/**
* Action Implementation: Send mail.
*/
function rules_action_mail($to, $subject, $message, $from = NULL, $langcode, $settings, RulesState $state, RulesPlugin $element) {
$to = str_replace(array("\r", "\n"), '', $to);
$from = !empty($from) ? str_replace(array("\r", "\n"), '', $from) : NULL;
$params = array(
'subject' => $subject,
'message' => $message,
'langcode' => $langcode,
);
// Set a unique key for this mail.
$name = isset($element->root()->name) ? $element->root()->name : 'unnamed';
$key = 'rules_action_mail_' . $name . '_' . $element->elementId();
$languages = language_list();

 if(!in_array($langcode,array_keys($languages)))
  {
	  $current_lang_dflt = language_default();
	  $langcode = $current_lang_dflt->prefix;
  };

$language = $langcode == LANGUAGE_NONE ? language_default() : $languages[$langcode];

$message = drupal_mail('rules', $key, $to, $language, $params, $from);
if ($message['result']) {
watchdog('rules', 'Successfully sent email to %recipient', array('%recipient' => $to));
}
}

winarcht’s picture

@FranckV:
I think your code should be like this:

if(!in_array($langcode,array_keys($languages)))
{
  $current_lang_dflt = language_default();
  $langcode = $current_lang_dflt->language;
};
ntigh52’s picture

when I try to add text in non english on the "Send an order notification e-mail" - drupal commerce, - I get the same error!
There is a solution for that?
whats wrong?
Thanks

ntigh52’s picture

Status: Needs work » Needs review

#10: rules_mail_lang.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, rules_mail_lang.patch, failed testing.

ntigh52’s picture

Hi all,
can I use the patch, rules_mail_lang.patch?
does this patch will solve the bug?
why the patch, rules_mail_lang.patch failed testing?
Thanks/

ntigh52’s picture

mitchell’s picture

Title: Undefined index in rules_action_mail() » Send mail action assumes i18n is in use and prodcues a non-fatal error
Version: 7.x-2.1 » 7.x-2.x-dev
Component: Rules Engine » Rules Core
Assigned: Unassigned » klausi
Status: Needs work » Reviewed & tested by the community

(14, 18, 19) confirm the fix in #10.

(21, 23-30) aren't related to the patch.

@21: Please open a separate issue and explain the context further.

rfay’s picture

#10: rules_mail_lang.patch queued for re-testing.

hmartens’s picture

Is there anyway I can get around this until the update is officially available?

Thanks guys for the help!

fago’s picture

Status: Reviewed & tested by the community » Fixed

Committed #10 , thanks.

Status: Fixed » Closed (fixed)

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