My horse has had ulcers and one of the things he does when he gets them is suck on his tongue as a coping mechanism, the tongue sucking produces foam sometimes. Ulcers are very painful and I have found that Gastro guard has worked wonders to heal them
My horse too! He REALLY depressed sometimes, and he stands in the back corner of the stall, but its NORMAL for a horse to foam at the mouth WHEN IT HAS A BIT IN IT MOUTH, but if hes foaming by him self, SEE A VET, CALL ANIMAL CONTROL!!
Have your horses teeth checked for infection.
Yours horse may have rabies, or if not your horse still has serious problems, go to the vet immediately!