Which preposition should go first? "for two hours" or "for her"? and why?
He has been writing a letter for two hours to her.
He has been writing a letter to her for two hours.
First, as people have pointed out in the comments "writing a letter to her" is much more natural than "writing a letter for her" [The question has already been edited to change this].
Secondly, both ways round are grammatical - but the "to her" is part of the pattern "write a letter to ...", so there is a strong preference for putting it closer to the verb than an adjunct (an optional extra) such as "for two hours".