I once resigned from a job because of bad management and a toxic environment (high employee turnover, employees were strong-armed into agreeing to unrealistic deadlines then held accountable, every failure always meant someone would have to take the blame and be scolded for it, etc). Because of false loyalty and a nurtured feeling of guilt, I waited too long and only resigned when it had already begun affecting my health (physically and mentally).

I made the mistake of trying to be honest. I explained why I felt that the work environment needed to be improved. I tried not to come across as accusatory and didn't blame anyone, just stating that the environment negatively affected my health and that it was likely the reason for other systemic problems (e.g. the high turnover) the company was facing and should be addressed.

Big mistake.

To keep a long story short, I ended up suing the company because they withheld payments arguing I owed them work (and in fact threatened to sue me over that). I would have likely won, but agreed to a settlement (that mostly consisted of them giving me money and me signing a statement that I had already turned in all property of theirs before quitting -- which wasn't really contested to begin with).

All in all, it wasn't worth it. I lost a budding friendship with a colleague who stayed with the company (and likely had to bear the fallout from my resignation) and the first couple of weeks after the resignation (before I decided to sue and was able to hand it all over to a lawyer) were a complete nightmare, even though I didn't spend a single day of it at the company.

Now there is a company out there where employees think badly of me because they were either hired during the fallout or were told stories about it if they joined after the fact. There's an employer who hates my guts and may have told others to avoid me. And there's a company I'll have to avoid working with (directly or not) in the future.

I'm sure there was no possibility of a "good" ending at the point I quit to begin with because my biggest mistake was holding out until I was too broken to leave gracefully. But I'm also pretty sure a simple "I'm leaving for greener pastures" type resignation could have at least avoided fuelling the fire.

Don't ever go into the details about why you're leaving. If anyone depends on you, make sure to find a graceful transition for them (if only by informing them well in advance), but don't ever say anything that implies they should have done things differently.

Despite what people say, most of them don't want your honest opinion. They just want to hear they've done nothing wrong. You're already causing a disruption for them by leaving, don't allow them to spin it into an attack. You're far more likely to make them think if you don't give them an opportunity to think of you as an aggressor (and if they will do so anyway, you have lost nothing).

On the flip side, the right time to bring up problems is while you are still intent on working there. If delivering outstanding work is not acknowledged, address it before you have decided to leave. As an employee, your opinion holds weight (because ignoring it may result in your resignation). If you've already resigned, you've already played your hand.

(If you do, however, maintain a friendship with your former employer, you may be able to talk to him about the reasons why you left, but not as an ex-employee at work, but as a friend -- preferably in a different environment altogether.)