The Shulchan Aruch (Orah Haim 206:3) rules that "Hirhur" – thinking words in one’s mind, without verbalizing them – is not considered by Halacha as actual speech, and therefore, one must actually verbalize a Beracha. Preferably, one should recite the Beracha audibly, such that he can hear the words, but at very least, he must actually recite the words with his mouth, and it does not suffice to simply think the words in one’ s mind. This ruling is in accordance with the view of the vast majority of Rishonim.
The notable exception is the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204), who famously ruled (in Hilchot Berachot 1:7) that one who merely thought the words of a Beracha in his mind has fulfilled the obligation, even though he did not actually recite the words with his mouth. This is also the view of the Samag (Rav Moshe of Coucy, France, 1200-1260).
Although Halacha does not follow the Rambam’s position, his view is nevertheless practically relevant in a case where one, for whatever reason, thought in his mind the words of the Beracha Aharona after eating. Hacham Ovadia Yosef writes in his Yabia Omer (vol. 4) that if a person drank, for example, and thought in his mind the words of "Boreh Nefashot," he does not then recite the Beracha. Although the Shulhan Aruch rules that thinking the words in one’s mind does not suffice, nevertheless, the Rambam’s view makes this situation one of "Safek Berachot" – where it is uncertain whether or not a Beracha should be recited. Therefore, one should not recite the Beracha.
Hacham Ovadia makes an exception in the case of one who ate bread, such that he must recite Birkat Ha’mazon, and he then thinks the entire text of Birkat Ha’mazon in his mind. If the person had eaten bread to the point of satiation, such that he must recite Birkat Ha’mazon on the level of Torah obligation, then he must then recite the text, since a Torah requirement is at stake, and he must therefore follow the stringent ruling of the Shulhan Aruch. (Quite obviously, this situation is very unlikely to arise, as it is difficult to imagine somebody thinking in his mind the entire text of Birkat Ha’mazon.)
Hacham Ovadia adds that this discussion applies only in the case of one who thought in his mind the words of the Beracha Aharona, after eating. If one thought in his mind the words of a Beracha before eating – such as, for example, the words of "She’ha’kol Niheya Bi’dbaro" – then the simple solution is to then decide that he does not wish to eat the food or drink the beverage. Since he only thought the words in his mind, and did not actually recite them, he is not considered to have recited a Beracha in vain by deciding not to eat. And then, later, when he decides again to eat, he recites the Beracha according to all opinions. Preferably, Hacham Ovadia writes, the person should recite "Baruch Shem Kebod Malchuto Le’olam Va’ed," which has the effect of "cancelling" the Beracha, in order to make it clear that he changed his mind about eating or drinking at that moment.
Summary: When one is required to recite a Beracha, he must verbalize the words; thinking the words in one’s mind does not suffice. However, if one did think the words of a Beracha Aharona in his mind after eating, he does not then recite the Beracha. If he had eaten bread in a quantity that requires reciting Birkat Ha’mazon on the level of Torah obligation, and he thought the words of Birkat Ha’mazon in his mind, he must then recite Birkat Ha’mazon. If one thought in his mind the words of a Beracha before eating, he should decide not to eat at that time, and should recite "Baruch Shem Kebod Malchuto Le’olam Va’ed." He then recites the Beracha when he later decides to eat.