Questions & Answers about Что ты ей вчера сказал?
Why is it ей instead of её?
ей is the Dative case form of она (she). Verbs of communicating, like telling (сказать), require the Dative case for the person receiving the information, because you are telling something to them. её is the Accusative form used for direct objects.
Why does the verb сказал end in a consonant if we are talking about a woman (ей)?
Is the word order strict here? Could I put the verb earlier?
You absolutely can! Russian word order is very flexible, so Что ты сказал ей вчера? is perfectly fine. However, the order in our example sentence is extremely natural in everyday speech. Putting the verb at the end places a slight focus on the action of telling.
What if I wanted to ask what you told him yesterday?
You would simply change the Dative pronoun ей (to her) to the masculine Dative pronoun ему (to him). The sentence would be Что ты ему вчера сказал?