You need to consider not just anonymity for people who don't want to donate, but convenience for those who do.
Do you also give out anonymous feedback forms?
If so, also give out envelopes for the feedback forms, and in the 5 minutes at the end of the class when people are filling out the feedback forms say about donations being welcome but not essential and if you want to donate, slip it in the envelope with the feedback forms.
Then have people pile up the envelopes on a table on their way out instead of taking them by hand, if you're concerned about anonymity of non-donors. This is anonymous and you can't feel which have coins or notes in. Don't rely on post as suggested elsewhere, that's an inconvenience, many people with the best intentions will simply never get around to posting it.
For extreme privacy, maybe even bring a cardboard box with a slot in the top for the envelopes, like a ballot box.
This is anonymous and gets around the problem with many other solutions of people wanting to donate but forgetting, finding it an inconvenience, or not getting around to it. You want maximum ease and convenience as well as maximum anonymity - for their benefit as well as yours.
If you don't, consider it and it might solve two common problems (donations and feedback).