Environmental exposures affect gamete function and fertility, but the mechanisms are poorly understood. Here, we show that pheromones sensed by ciliated neurons in the Caenorhabditis elegans nose alter the lipid microenvironment within the oviduct, thereby affecting sperm motility. In favorable environments, pheromone-responsive sensory neurons secrete a transforming growth factor-β ligand called DAF-7, which acts as a neuroendocrine factor that stimulates prostaglandin-endoperoxide synthase [cyclooxygenase (Cox)]-independent prostaglandin synthesis in the ovary. Oocytes secrete F-class prostaglandins that guide sperm toward them. These prostaglandins are also synthesized in Cox knockout mice, raising the possibility that similar mechanisms exist in other animals. Our data indicate that environmental cues perceived by the female nervous system affect sperm function.