Well, for starters, the force acts on the entire magnet, but it acts most strongly on the portion closest to the other magnet. The short answer to how the force is transmitted is through a magnetic field. It’s a little more complicated than the electric field, which is the gradient of the electric potential; there is such a thing as a magnetic potential, but it’s a vector, not a scalar, and the field is the curl of the potential, not the gradient. If you’re not familiar with curls and dels and all that mathematical stuff, then disregard that; it’s similar to the electric field but more complicated.
As to why it works: A bar magnet has a bunch of electrons spinning in circles in it, like a bunch of current loops. Each loop acts like a bar magnet, itself, so to simplify the problem, let’s say that each of our magnets is a single loop of wire, with a current moving through each. A segment of the two wires might be represented like this:
+ + + + + + + + + + +
- - - - - - - - - - -
+ + + + + + + + + + +
- - - - - - - - - - -
where the + signs represent positively charged nuclei, and the - signs represent negatively charged electrons, moving to the right in both wires. However, these electrons are moving, so let’s take a look at the wires from the frame of reference of the electrons. In this reference frame, the positive nuclei seem to be moving to the left, and because of relativistic effects, the distance between them appears to be shorter:
++++++++++++++++++++++
- - - - - - - - - - -
++++++++++++++++++++++
- - - - - - - - - - -
The spacing of the electrons is normal, because they’re all moving with the same velocity, so in that reference frame, they’re all stopped, and there’s no relativistic effects. In other words, to an electron in one of the wires, it looks like the other wire has more positive charges than negative ones, so each electron is attracted to the other wire. On the other hand, if we look at it from the point of view of the positive charges, it’s the electrons that are moving, and therefore scrunched together:
+ + + + + + + + + + +
---------------------
+ + + + + + + + + + +
---------------------
so to a positive charge, it looks like the other wire is negative, so the positive charges are attracted to the other wire, too.
If these wire segments are part of a couple of loops, it’s slightly more complicated: The total number of protons and electrons must still be the same, and on the other side of the loop, the electrons are moving the other way, so the effect is reversed: It looks to an individual electron in one loop like the other loop is positive on the near side, and negative on the far side. However, since the electric force falls off with distance, the force from the near side of the other loop is stronger, so the net force is attractive.
Note also that the diagrams are greatly exaggerated here, and the relativistic effects are actually very small: Electrons in a wire typically only move at a few centimeters a second, which is MUCH less than the speed of light. Usually, we can completely ignore relativistic effects at these speeds, but they’re there, and when you take septillions of electrons, it starts to really add up.