Earth is part of Solar system, which is said to have originated from condensation and mutual attraction in dense clouds of gasses and dust. If Sun is basically more than ninty percent hydrogen and rest is helium. Nuclear fusion inside sun is said to pause near iron(56/26) and also several other planets like Jupiter and Saturn are gas giants. Where did heavy metals and other heavy elements on earth come from if second most nearest star(/star-system) is some four light years away (and mass would take long to come from those sources) ?
Different types of stars are responsible for creating different groups of elements via nucleosynthesis. Most of the "lighter" metals (Na, Al, Ga, Ge, Se), were formed by exploding massive stars, and most of the "heavier" metals (I, Ir, Ag, Au, Pt, U, Pu) were created by merging neutron stars. Exploding white dwarfs are partially responsible for elements like Ti, V, Cr, Fe, Co, Ni. Dying low mass stars were involved with the creation of some of the elements Sr, Y, Zr.
The following periodic table of elements (from Wikipedia), shows the elements color coded according to their source of creation.
All the elements on Earth were created by various stars that seeded our region of the universe prior to the formation of our solar system.
A very quick answer -- someone else may have a better and more referenced one. The heat of the newly formed sun drove the light elements away from the inner system (mostly). The rocky planets formed from what was left, the relatively small proportion of heavier elements in the dust and gas. Those elements were there at all because previous generations of stars, some much larger than the Sun, as well as violent events like neutron star collisions, had released them into space, contaminating the primordial clouds of hydrogen and helium.
Supernova ejecta expand at velocities between 5,000 km/s and 30,000 km/s. Lets take 10,000 km/s as typical. The speed of light, c, is 300,000 km/s, so 10,000 km/s = c/30. So, it would take 120 years for metals from the nearest stars to get to the Sun. How much time was available? Star formation in galaxies was well along 1 billion years after the Big Bang, 12.7 Gyr ago, and the Sun is 4.7 Gyr old. So that gives 8 Gyr of travel time for debris from the first massive stars which become supernova in less then 100 million years. Thus, the traveled length of the debris is 8 Gyr * c/30 is about 270 million light years. In other words, there was sufficient time for supernova debris from our galaxy and hundreds of other galaxies to reach the solar protoplanetary nebula. The story of course is different for the metals that come from progenitors that are not massive stars because of the longer delay for them to form.
I should add that the debris is likely to encounter intergalactic material along the way which will eventually halt its motion. So realistically material will rarely move quite that far.
From an analysis of a certain type of Gamma-ray burst (Short, Hard GRB's) it is speculated these are caused by merging neutron stars. It is also theorized that 2 merging neutron stars can create elements, some of the heaviest ones included. This may have increased the amount of gold and other heavy elements on earth. These merging neutron stars also cause the r-process to create heavy elements due to a large number of neutrons.