P.M.
This is such a difficult issue after fear of pain has set in. My grandson, now 5, still occasionally has problems, but he's old enough now to deal with it better.
A few suggestions:
I'd have a talk with her and assure her you understand her fear, and that lots of little kids have this problem, so she's not alone. It simply never works to tell a child (or an adult) that they shouldn't be afraid; that simply invalidates their feelings and can leave them feeling even more alone with their problem.
Read "It Hurts When I Poop." This book has helped many, many children deal with painful pooping. Another amusing and educational book that may help in tandem is "Everybody Poops." Amusing distraction can be helpful.
If she'll sneak off to go in her pants, she'll probably go in a diaper. tell her it's okay to use a diaper for pooping until things get easier. I've known many, many parents who offer diapers for a range of potty issues, and they don't appear to confuse the child or cause backsliding. Be clear that the diaper is only for help with the pooping. Easier on her, less cleanup for you.
For very occasional use, a children's liquid suppository can make it virtually impossible to withhold the poop, and add some lubrication. Kids do not like this solution and will probably fight it, but my grandson was always relieved and grateful when the ordeal was over. Emergency only – this can be habit forming.
Teach breathing (like for childbirth) when your daughter is having a hard time eliminating. My gs really takes to this. Inhale through nose, blow out slowly through mouth. Sometimes just having a tool that they believe will help can make a much easier experience.
Plenty of water throughout the day. This in addition to plenty of fiber-rich foods and are the most reliable solution for my grandboy. Fiber alone can actually make constipation worse, poops bigger.
Good luck. Your sweetie sure does have my sympathy.