Yes he said it (assuming that the translation from the Hindi, and Project Gutenberg, can be trusted).
The quote can be found early in "Chapter VI - CONTAGIOUS DISEASES: SMALL-POX" of:
A GUIDE TO HEALTH BY MAHATMA GANDHI
Translated from the Hindi
A. RAMA IYER, M.A.
Published in Madras in 1921 and republished as a Project Gutenberg EBook.
The exact quotes (copy and pasted from Project Gutenberg) are,
Vaccination is a barbarous practice, and it is one of the most fatal of all the delusions current in our time, not to be found even among the so-called savage races of the world.
Those who are conscientious objectors to vaccination should, of course, have the courage to face all penalties or persecutions to which they may be subjected by law, and stand alone, if need be, against the whole world, in defence of their conviction.
FYI here are some other quotes from the introduction and first two chapters of the same source. I chose quotes which don't really agree with my more 'modern' understanding of physiology. The added emphasis in each passage is mine:
We have got into the habit of calling in a doctor for the most trivial diseases. Where there is no regular doctor available, we take the advice of mere quacks. We labour under the fatal delusion that no disease can be cured without medicine. This has been responsible for more mischief to mankind than any other evil. It is of course, necessary that our diseases should be cured, but they cannot be cured by medicines. Not only are medicines merely useless, but at times even positively harmful. For a diseased man to take drugs and medicines would be as foolish as to try to cover up the filth that has accumulated in the inside of the house. The more we cover up the filth, the [Pg 5] more rapidly does putrefaction go on. The same is the case with the human body. Illness or disease is only Nature’s warning that filth has accumulated in some portion or other of the body; and it would surely be the part of wisdom to allow Nature to remove the filth, instead of covering it up by the help of medicines. Those who take medicines are really rendering the task of Nature doubly difficult. It is, on the other hand, quite easy for us to help Nature in her task by remembering certain elementary principles,—by fasting, for instance, so that the filth may not accumulate all the more, and by vigorous exercise in the open air, so that some of the filth may escape in the form of perspiration. And the one thing that is supremely necessary is to keep our minds strictly under control.
Thus considered, we may conclude that that man alone is perfectly healthy whose body is well formed, whose teeth as well as eyes and ears are in good condition, whose nose is free from dirty matter, whose skin exudes perspiration freely and without any bad smell, whose mouth is also free from bad smells, whose hands and legs perform their duty properly, who is neither too fat nor too thin, and whose mind and senses are constantly under his control. As has already been said, it is very hard to gain such health, but it is harder [Pg 11] still to retain it, when once it has been acquired. The chief reason why we are not truly healthy is that our parents were not. An eminent writer has said that, if the parents are in perfectly good condition their children would certainly be superior to them in all respects. A perfectly healthy man has no reason to fear death; our terrible fear of death shows that we are far from being so healthy. It is, however, the clear duty of all of us to strive for perfect health. We will, therefore, proceed to consider in the following pages how such health can be attained, and how, when once attained, it can also be retained for ever.
The world is compounded of the five elements,—earth, water, air, fire, and ether. So too is our body. It is a sort of miniature world. Hence the body stands in need of all the elements in due proportion,—pure earth, pure water, pure fire or sunlight, pure air, and open space. When any one of these falls short of its due proportion, illness is caused in the body.
The most important portion of the body is the stomach. If the stomach ceases to work even for a single moment, the whole body would collapse. The work of the stomach is to digest the food, and so to provide nourishment to the body. Its relation [Pg 13] to the body is the same as that of the steam engine to the Railway train. The gastric juice which is produced in the stomach helps the assimilation of nutritious elements in the food, the refuse being sent out by way of the intestines in the form of urine and fæces. On the left side of the abdominal cavity is the spleen, while to the right of the stomach is the liver, whose function is the purification of the blood and the secretion of the bile, which is so useful for digestion.