How to prevent a Rules Action to happens twice using Rules Event User account validated?

by Andrew Morris   Last Updated April 10, 2017 14:07 PM


As Molot has pointed out this isn't anything to do with emails, just the rule happening twice. I'll leave the text below incase anyone else is trying to send out emails on verification and they come to the same conclusion I did, so they can find this and understand whats happening

I've set up a rule that sends you an HTML email when you activate your account. It seems to throw back a notification about:

Notice: Undefined variable: attachment in SmtpMailSystem->mail()

But it seems to send the email anyway, but what I don't understand is that I receive 2 emails everytime I test it. I've checked the log files and it seems to log that an anonymous user has used the validate URL to confirm their email address, then sends the email. Then it opens up a session for this new user, and then sends them the email again.

I've set the rule to run on 'When the user account is activated' and if I turn the rule off I get no emails, so it isn't that there is anything else sending an email too, it is only this rule, it just seems to do it twice.

Can anyone offer a solution?

I'm using the SMTP, Mimemail and Mail System modules

If anyone needs me to post any specifics about the rule, or the error or the email text etc, just ask, I just didn't want to flood the post with huge blocks of code if it might not have helped.


Log file output (obviously I have flipped the order for it to make sense, log files are recent most recent first)

  • New user: unset_username ( // When I create a new account
  • Sending mail to: "Firstname Lastname" // Emails out the verification request
  • E-mail validation URL used for Firstname Lastname with timestamp ...
  • Sending mail to: "Firstname Lastname" // Emails out the confirmation email once
  • Session opened for Firstname Lastname.
  • Sending mail to: "Firstname Lastname" // Emails out the confirmation email again


Determined the issue is nothing to do with the emails, tried re-creating the rule but sending an output to the page rather than sending HTML email, it was confirmed that this rule runs twice (and hence nothing to do with emails in particular) by the fact that the message was output twice as well.

Tags : 7 rules email actions

Answers 1

Your question seems like a variation (IMO not a duplicate) of the question 'Why is my rule that reacts on event "After updating an existing user account" firing twice?'. The accepted answer in that question might help to understand your issue (what's causing it) also, ie:

some other module code is calling a user_save on hook_user_update triggering the rules event a second time.

If I was to debug this, I'd disable all contributed modules (except "Rules" and "Entity API") to check if it's indeed a contributed module (I don't expect it to be core). And then re-enable the contributed modules one by one until the issue comes back. As soon as it comes back, you pinpointed the contributed module causing the issue, and you can start working on a possible remedy for that.

That question also has another answer with a very interesting workaround, with an image which looks like so (a picture is worth more then 1000 words):

enter image description here

February 06, 2017 09:07 AM

Related Questions