Flowers smell pleasant because they use their scents to attract pollinators, communicate with other plants, and for some carnivorous species, lure in food.
The part of the plant that releases fragrance depends upon the species. For many flowering plants, the production of odor is spread throughout the outer layer of petals and other parts of the flower. Some flowers such as orchids have specialized glands called osmophores that ooze liquid scent, which evaporates on contact with the air.
Some flowering plants use their odors to entice a host of insects and birds to fertilize their flowers.
The creation of scent is actually a balancing act: plants must generate enough smell to induce insects to fertilize their flowers, but not so much that they waste energy and carbon.