The phalanx do indeed hurt the elephants. Plain vanilla elephants can charge through a base level phalanx though, but not the larger better types of hoplite. They take casualties doing it (unusual for elephants.) And as I meant to say in my original reply to Oleander, those large phalanx with longer spears can completely halt the elephants and/or kill them immediately, just like he said.

As you say, though, the mobility issue means that it is going to be tough to use phalanx as an effective counter.