Thanks for using JustAnswer.com, I'm Dr. Dan and I'll try to help you.
Is your dog coughing and then bringing up the white foam or is the vomiting separate from the coughing?
How long has this been going on?
Thanks for the information.
This sounds like a pretty standard upper respiratory infection... some people label this kennel cough. Dogs will get an irritation in the upper airway and cough to clear the irritation. The hard coughing collects some of that foam and they hack/gag it up. The lethargy and not eating is usually due to the fever that comes along with the cough. These coughs are often due to viruses or bacteria that are picked up somewhere in the environment or from other dogs. The best thing to do is to have your vet examine him ASAP as usually antibiotics are required. In the meantime you should put him in a bathroom with a hot running shower so he can breathe in the warm steam for 10-15 min. Then take him in to the vet when you can.
I hope this helps, best wishes.