The Sun formed as part of a cluster of stars which condensed out of the gas and dust present in our Galaxy. It would have also picked up material from earlier stars which had exploded because of their massive size. The planets were formed at the same time. The first generation stars contained just hydrogen and helium and not much else. When they exploded as supernovae, the heavier elements such as lead, copper, gold and everything else were created so without those first stars we could not exist.