Quote from andread:
Not so easy to explain in two lines. It basically works like this: you go to site A. You log in. Site B, via site A, can send you a cookie. Now you go to site C. Site B, via site C, and the cookie, can tell that you are now visiting site C. Because you logged in on site A, they know it's you (if site A gives information about you to site B, which shouldn't happen very often). Besides, site A and site C have to let site B put some content on their site to send cookies. If you let the cookie stay on your machine, that is, you don't keep it just until the end of the session, they can track you for days.
There is a lot of information on the internet. Just google for "tracking cookies"
I honestly don't think it's very likely that you are getting spam because of tracking cookies