It's far too easy to look at the demographics of the different voters and say "They're less educated, and older, and poorer, of course they voted against their best interests." - but it's (a) not as simple as that and (b) that doesn't explain _why_ those factors would lead to people voting themselves out of the EU. After all, if what we were talking about was simple ignorance then the results should be random at lower levels of education, not anti-Europe.
The problem as I see it is that there are groups of people who believe they have either gained nothing from the changes in society over the last few decades, or have actively lost out. Those people are now a large enough proportion of the population that their angry lashing out is capable of tipping the scales of power.
There were less of the disenfranchised during the Blair years because the economy was constantly growing, and therefore (nearly) everyone felt a little bit better off, and even if things weren't better _now_ there would clearly be opportunities in the future. But when the growth stops then you're either in a worse state than before, or suddenly realising that the current shitty situation is one you're stuck with.
And the problem is that nobody ever told them the truth. Nobody ever said that if we wanted Europe to be a success then everyone would have to pay for it, and that would mean us paying more than we got back - but it would be worth it for the peace and the possibilities it opened up. Instead we were told that everything we did would benefit us directly.
When, of course, we were told at all. If you weren't paying attention then it would be hard to tell that New Labour were working to improve poverty at all. They were - but it was all being done in such a hush-hush, don't let the Daily Mail find out that we're actually left-wing manner, that when they finally ended their winning streak it was remarkably easy for the Conservatives to roll things back, because almost nobody could see what we were losing. Unless they were directly affected, of course.
And, of course, they didn't sell the benefits of Europe either. Labour have been pretty content to just let Europe slide by in the background, not worrying about it. And, frankly, so was I. Because it felt remote, and had been around since before I was born, it was something I didn't really think about. Like, say, oxygen.
The problem with that, is that when it comes to taking a vote on whether we should have oxygen any more, I haven't actually thought much about why I care about it, and what it means to me. And when the anti-oxygen side keep pointing out that without it we'd have a lot less forest fires, you can't actually get the general population up to speed on why they should vote to keep it.
As usual, I see this at least partially as a democracy/voting issue. With the system we have it's easiest for Labour (for instance) to take anywhere that doesn't vote Conservative for granted, and not mention any policies/areas that might upset people. So even though the poorest people in rural areas might actually be doing badly, nobody is going and talking to them, and the resentment festers until it explodes when given a chance to "Teach them all a lesson". Given a system where people can vote for what they see as their self-interest, we might actually see parties working harder to include everyone, and to listen to people's problems. And a system that doesn't assume that because it works for the majority it can ignore those on the fringes.
You will, of course, always have some really racist people. But the majority, in my opinion, are going along with self-interest, wanting to protect themselves because they don't feel protected by the people who claim to represent them. If we want to defang the awfulness that we're seeing at the moment then we need a better understanding of the real reasons why they don't feel like the system works for them, and to improve the system so that it works for everyone, and is seen to work for them.
(For another take on this, see this article, which I found fascinating.)