A second potential cause for foaming around the mouth is stress or anxiety.
Dogs who are feeling unsettled often begin drooling excessively.
Much like when they're playing, a stressed or anxious dog may begin panting, which, when combined with the drool can cause foaming to occur.