Still confused about putting 了 at the end of a sentence or right after the verb
The order where 了 appears in the sentence is important: when placed at the end of a sentence, it represents a change of state (it has nothing to do with tenses); when placed at the end of a verb, it represents a completed action. Using the examples in your question:


他们给我写信了 They wrote me a letter. (This is the first time I receive
a letter from them.)
他们给我写了信 They have written me a letter. (This is the fifth letter
from them.)
她给我们买巧克力了 She bought us chocolate. (It has been a long while since she last treated us.)
她给我们买了巧克力 She just bought us chocolate. (Oh, she bought some yesterday too.)