I was just showing a minus sign that you missed, that's all.
$e1 = 1 / (1 + pow(10, ($p2 - $p1) / 400));
may seem to be just like writing
$e1 = 1 / (1 + pow(10, -($p2 - $p1) / 400));
but it's not. The two give different results. The second "seems" to be the correct one, but if you say it isn't I won't disagree.
As for the rest: I'm sure the original poster will be glad to hear it.