Mate recognition in animals evolves during niche adaptation and involves habitat and social olfactory signals. Drosophila melanogaster is attracted to fermenting fruit for feeding and egg-laying. We show that, in addition, female flies release a pheromone (Z)-4-undecenal (Z4-11Al), that elicits flight attraction in both sexes. The biosynthetic precursor of Z4-11Al is the cuticular hydrocarbon (Z,Z)-7,11-heptacosadiene (7,11-HD), which is known to afford reproductive isolation between D. melanogaster and D. simulans. A pair of alternatively spliced receptors, Or69aB and Or69aA, is tuned to Z4-11Al and to food olfactory cues, respectively. These receptors are co-expressed in the same olfactory sensory neurons, and feed into a neural circuit mediating species-specific, long-range communication: the close relative D. simulans does not respond. That Or69aA and Or69aB have adopted dual olfactory traits highlights the interplay of habitat and social signals in mate finding. These olfactory receptor genes afford a collaboration between natural and sexual selection, which has the potential to drive phylogenetic divergence.