The evolution of behavioral isolation is often the first step toward speciation. While past studies show that behavioral isolation will sometimes evolve as a by-product of divergent ecological selection, we lack a more nuanced understanding of factors that may promote or hamper its evolution. The environment in which mating occurs may be important in mediating whether behavioral isolation evolves for two reasons. Ecological speciation could occur as a direct outcome of different sexual interactions being favored in different mating environments. Alternatively, mating environments may vary in the constraint they impose on traits underlying mating interactions, such that populations evolving in a "constraining" mating environment would be less likely to evolve behavioral isolation than populations evolving in a less constraining mating environment. In the latter, mating environment is not the direct cause of behavioral isolation but rather permits its evolution only if other drivers are present. We test these ideas with a set of 28 experimental fly populations, each of which evolved under one of two mating environments and one of two larval environments. Counter to the prediction of ecological speciation by mating environment, behavioral isolation was not maximal between populations evolved in different mating environments. Nonetheless, mating environment was an important factor as behavioral isolation evolved among populations from one mating environment but not among populations from the other. Though one mating environment was conducive to the evolution of behavioral isolation, it was not sufficient: assortative mating only evolved between populations adapting to different-larval environments within that mating environment, indicating a role for ecological speciation. Intriguingly, the mating environment that promoted behavioral isolation is characterized by less sexual conflict compared to the other mating environment. Our results suggest that mating environments play a key role in mediating ecological speciation via other axes of divergent selection.