The planets are composed of material quite different from the Sun. The Sun is almost entirely composed of hydrogen, and some helium. Its energy comes from the conversion of hydrogen to helium. In contrast, the "terrestrial" planets are composed almost entirely of larger atoms and molecules which "cannot" have come from the Sun. It follows, therefore, that the material which forms those planets must have come from another source or sources. Those sources were the atoms formed in supernovae explosions by much larger and much shorter-lived stars in the Sun's neighbourhood as it moved in the galaxy. This material was captured by the Sun's gravity and pulled along to become the basic material out of which the planets condensed. The same considerations apply to other planetary systems in the galaxy.