They are both fine. Putting the preposition at the end is perhaps a bit more natural, although some old-fashioned grammarians used to object to this, apparently based on principles of Latin grammar. (I think no one seriously believes this any more.)
Actually, what most people would say (but perhaps not write) in everyday contexts is "Who did you speak to?" but those same grammarians would probably object to that too, and on perhaps somewhat more reasonable grounds.