Kinda, but not quite.
A planet, even a small one like Mercury, does exert a gravitational effect on any other object anywhere in the universe, whether it's a spacecraft flying by Jupiter, a rock in your back yard, or a star 5 million light years away.
However, the force exerted on an object due to gravity from another object is proportional to how far apart they are. In other words, the farther away you get from Mercury, the lower its gravitational pull on you. If you were over in the vicinity of Jupiter, the gravitational pull of Jupiter will be many millions times more significant than the gravitational pull of Mercury.. so you won't "fall into" Mercury from deep space.
It's possible that you could slowly be pulled towards the Sun if the net gravitational pull was in that direction... and you could pass very close to Mercury and get caught in its gravitational field and pull you into Mercury, but that is quite unlikely.
so an object travelling at the speed of light would NOT be acknowledgingly pulled drasticley toward a planet/star/object.
maybe my first message was miss-understood by some people, the spaceship i speak of WOULD have an engine, im merely saying it would only need to be functional, burning up fuel etc for a second to get to the speed and then being in space with no friction to slow the object down it would drift off in a direction at the speed of light. INSTED of keeping a engine constantly running like a car engine because of air/tire friction/gravity to slow it.
I guess the planets small gravity pulls on the object travelling at light speed a little and may slow it down eventually...... hmm, but if it was in interstellar space the gravitational pulls on the object would be so small that it would take years for it to slow it down. + after 5 years i think we'd hit a neighbour system and want to slow down to explore/take pics etc.