This picture shows what happens when the molecules coming from the comet encounter interplanetary space.
The comet's interaction with interplanetary space, part 2
How Particles are Swept into the Tail
The magnetic field of the sun (the IMF) is distorted in passing over the comet, taking a long time to slip around the sizeable ion cloud which forms the comet coma. The stretched magnetic field lines form a long tail region as they slip around the nucleus, before finally straightening out, about a million miles later, to their original configuration.
Ions from the nucleus begin to circle around the field lines of the IMF and are thus carried into the tail region created by the stretched magnetic field lines. Once they begin gyrating around the magnetic field, ions are "stuck" to the field lines.
The movie below shows this process at work.