run transaction first so emails don't get sent if there's an error