The channel kinases TRPM6 and TRPM7 have recently been discovered to play important roles in Mg2+ and Ca2+ homeostasis, which is critical to both human health and cell viability. However, the molecular basis underlying these channels' unique Mg2+ and Ca2+ permeability and pH sensitivity remains unknown. Here we have created a series of amino acid substitutions in the putative pore of TRPM7 to evaluate the origin of the permeability of the channel and its regulation by pH. Two mutants of TRPM7, E1047Q and E1052Q, produced dramatic changes in channel properties. The I-V relations of E1052Q and E1047Q were significantly different from WT TRPM7, with the inward currents of 8- and 12-fold larger than TRPM7, respectively. The binding affinity of Ca2+ and Mg2+ was decreased by 50- to 140-fold in E1052Q and E1047Q, respectively. Ca2+ and Mg2+ currents in E1052Q were 70% smaller than those of TRPM7. Strikingly, E1047Q largely abolished Ca2+ and Mg2+ permeation, rendering TRPM7 a monovalent selective channel. In addition, the ability of protons to potentiate inward currents was lost in E1047Q, indicating that E1047 is critical to Ca2+ and Mg2+ permeability of TRPM7, and its pH sensitivity. Mutation of the corresponding residues in the pore of TRPM6, E1024Q and E1029Q, produced nearly identical changes to the channel properties of TRPM6. Our results indicate that these two glutamates are key determinants of both channels' divalent selectivity and pH sensitivity. These findings reveal the molecular mechanisms underpinning physiological/pathological functions of TRPM6 and TRPM7, and will extend our understanding of the pore structures of TRPM channels.