One possible explanation for the widespread existence of cooperation in nature is that individuals cooperate to establish reputations and so benefit in future interactions with others. We consider a class of games in which individuals contribute to a common good at a cost to themselves. Population members vary in type, that is, in the cost paid for a given level of contribution. We consider a form of indirect reciprocity in which the contribution of an individual depends on their partner's reputation and their own type. Here we show that for such games, reputation destabilizes the selfish equilibrium through a novel and robust feedback mechanism. For those games in which the selfish optimal contribution to the common good increases as the contribution of the partner increases, the feedback mechanism enhances cooperation levels. In contrast, when the optimal contribution decreases as partner's contribution increases, cooperation levels are reduced still further.