Error when rendering a template (for HTML email) on users.saveUser I'm writing a simple project-specific plugin that sends a notification to the site admin when a new user is registered. I have an HTML template that I'd like to use for this.

In my plugin's main class, I have the following function:

public function init()
    {
        parent::init();
        // Events
        craft()-&gt;on('users.saveUser', function(Event $event) {
            $user = $event-&gt;params['user'];
            $isNewUser = $event-&gt;params['isNewUser'];

            if ($isNewUser)
            {
                // Send notification email
                craft()-&gt;aeiMember-&gt;registrationNotification($user);
            }
        });
    }


which calls a one of my plugin's services, 'registrationNotification'. Here's the code I have for that service:

public function registrationNotification(UserModel $savedUser)
    {
        $user = new \stdClass();

        $user-&gt;firstName            = $savedUser-&gt;firstName;
        $user-&gt;lastName             = $savedUser-&gt;lastName;
        $user-&gt;email                = $savedUser-&gt;email;
        $user-&gt;aeiGroups            = $savedUser-&gt;aeiGroups;
        $user-&gt;phone                = $savedUser-&gt;phone;
        $user-&gt;mailingAddress       = $savedUser-&gt;mailingAddress;
        $user-&gt;city                 = $savedUser-&gt;city;
        $user-&gt;state                = $savedUser-&gt;state;
        $user-&gt;zip                  = $savedUser-&gt;zip;
        $user-&gt;country              = $savedUser-&gt;country;
        $user-&gt;preferredDealer      = $savedUser-&gt;preferredDealer;
        $user-&gt;dealerAccountNumber  = $savedUser-&gt;dealerAccountNumber;
        $user-&gt;school               = $savedUser-&gt;school;
        $user-&gt;expectedGraduationDate = $savedUser-&gt;expectedGraduationDate;

        $email = new EmailModel();
        $email-&gt;toEmail = '...myemailaddress...';
        $email-&gt;subject = 'New User Registration: ' . $user-&gt;firstName . ' ' . $user-&gt;lastName;
        $email-&gt;htmlBody = craft()-&gt;templates-&gt;render('aeiMember/registration_notification', array(
            'user' =&gt; $user,
        ));

        // Send
        if (craft()-&gt;email-&gt;sendEmail($email))
        {
            return true;
        }
    }


When I submit the registration form, I get the following error: "CDbException: CDbTransaction is inactive and cannot perform commit or roll back operations.". I narrowed down the issue, and if I use a non-HTML email body, everything works fine, so apparently there's an issue with rendering a template at this event.

Here's a link to a Google Doc with the stack trace: https://docs.google.com/document/d/1atFNkktuZQ91hU9QipXYMhOCHNGAavO5qUI_TF5jSeE/edit?usp=sharing

Am I doing something wrong, or is there a workaround to accomplish what I'm after? It seems like it should be pretty simple.
The issue turned out to be the result of a variable name mistake on my part. I had typed in an incorrect variable name in the email template. I actually still don't really understand what that has to do with a database transaction, though.

EDIT:
If anyone else is running into a similar issue, I've found a way to get a more useful error message, as opposed to the "CDbTransaction is inactive" message, which doesn't help much. If you go to craft/app/services/UsersService.php, and comment out line 311 ("$transaction->rollback();"), then Yii won't give you the CDbTransaction error before Craft has a chance to tell you its more helpful error. This should give you a better idea of what you're doing wrong. Obviously, don't forget to un-comment that line after you've fixed your issue.