Commerce / Rules - commerce-order:mail is empty for anonymous users I'm having trouble sending order notification emails to anonymous users. As a bare-bones test I have created a new rule which triggers on 'Completing the checkout process', checks if the current user is authenticated, and if not sends an email to [commerce-order:mail]. When it's triggered I get the following error message, suggesting it is not able to get the email address from the order.

Error sending e-mail (from admin@ourwebsite.com to ).

I'm fairly sure the problem isn't to do with Rules config as it's so simple, but here is the export anyway:

{ "rules_anonymous_order_notification" : {
"LABEL" : "Anonymous Order Notification",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "Commerce Checkout" ],
"REQUIRES" : [ "rules", "commerce_checkout" ],
"ON" : { "commerce_checkout_complete" : [] },
"IF" : [
  { "NOT user_has_role" : {
      "account" : [ "site:current-user" ],
      "roles" : { "value" : { "2" : "2" } }
    }
  }
],
"DO" : [
  { "mail" : {
      "to" : [ "commerce-order:mail" ],
      "subject" : "Order received!",
      "message" : "This is to tell you the order has been received.",
      "language" : [ "commerce-order:state" ]
    }
  }
]


}
}

What else could be causing this?

EDIT: I've just noticed in the db the mail column is empty for anonymous orders in 'commerce_order' - is this normal?
Have a look at issue # 430274, about an event which is a variation of your event here, and somehow explains that "after saving something" actually happens ... "before saving something" (which is not a bug, simply how the Rules module  works ...).

A possible compromise to avoid these kind of issues, is to transform what you're trying to do in your Rules Action in a Rules Component, so that your Rule "schedules the execution" (using the Rules Scheduler submodule) of that Rules Component. For example after only a few seconds or minutes later on (if your cron job runs frequent enough, otherwise it'll be next time cron runs). This compromise will ensure that, at the time the Rules Component is executed, the "Checkout process" for sure completed, and your "eMail ID" will have been updated as expected.

Rules debugging

If none of the above helps, then move on to Rules debugging, as explained in my answer to "How can I display the value of a variable inside a condition?".

Depending on what the result of that type of debugging is, you may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value" (in your case of your commerce-order:mail). It may help to check if the cause of your problem is because of what is written in the comments from james, i.e.:


  anonymous user won't be having any mail, that is why the commerce order also not having any mail. There is an option in commerce to allow the user to login while checkout. I believe the functionality works fine. I usually ask user to login before proceeding to checkout itself. So, I have never faced the above mentioned issue with commerce and rules.