Any time a horse is unwilling to eat, there is reason for concern.
With foam coming from his mouth, one of the first problems to consider is choke (a blockage in the esophagus). If the problem does not resolve in an hour, your veterinarian will need to pass a stomach tube to check/resolve the choke.
Other possibilities that need to be considered are colic, respiratory problems, foreign bodies in the mouth/tongue, etc. All these problems are made worse in the heat of summer, when dehydration also becomes a concern. In any of these cases, it is best to contact your veterinarian.