Reasons why a cat foams at the mouth:
1. The cat accidentally ate something unclean.
Cats may vomit white foam if they accidentally ingest something unclean, as they try to expel the contaminated food. Giving them some clean water can help cleanse their digestive system. Once they vomit, they will gradually recover.
2. Poor digestion
Cats are very prone to indigestion if they eat spoiled or too much hard-to-digest food. The white foam that a cat vomits may be gastric juice. If the cat vomits undigested or digested food in addition to white foam, then the vomiting is caused by a digestive problem. 
3. Gastroenteritis
When cats have gastroenteritis, they may foam at the mouth, become lethargic, lose their appetite, and even vomit blood. In such cases, you can give them a medication like Evodia rutaecarpa, which has antiemetic, stomach-protecting, anti-inflammatory, and antibacterial properties, and can help prevent and treat gastrointestinal inflammation, aiding in the cat's recovery.
4. Hairballs
Cats love to groom themselves. This fur is often swallowed by cats and is difficult to digest, eventually forming hairballs in their bodies. Hairballs can also cause vomiting in cats. If a cat is foaming at the mouth and constantly dry heaving, it's very likely that the hairball is too large for the cat to vomit, causing the foaming.