Breast becomes hard and painful and later I get a small fever

First time it happened, I took antibiotics and the fever went and the breast pain went after a few days. Now it has happened again on the other breast. The one he usually loves. First time it was the breast that had more painful nipples so I thought I didn't feed him enough on that.

Question is, why do breasts harden and why does it cause.me a fever. How can I prevent this?

Thanks ladies for the advice. Can I get an infection within 5 hours of the onset of the pain? Like that fast?