In this study, a novel surfactant with pH-responsive properties was developed to address the challenges associated with balancing foaming and defoaming properties in traditional foam drainage gas recovery processes. The surfactant was created by employing primary amine and aldehyde monomers based on the principles of reversible dynamic covalent bonds. Optimal synthesis conditions were determined through an extensive analysis of foaming performance: a molar reaction ratio of primary amine to aldehyde at 10:0.8, a 20-minute reaction time, and a stirring speed of 300 r/min.The formation of dynamic imine bonds was confirmed through infrared spectroscopy. Surface tension measurements revealed that at pH = 8, the surfactant achieved a minimum surface tension of 31.1 mN/m, while at pH = 3, the surface tension exceeded 40 mN/m. Particle size analysis demonstrated a 26.5-fold reduction in particle size as the pH decreased from 8 to 3. Zeta potential tests indicated excellent dispersion stability within the pH range of 3–8, with Zeta potential consistently exceeding 25 mV.Furthermore, the surfactant displayed remarkable foaming and foam stabilizing effects at pH = 8, with initial and 5-minute foam heights reaching 168 mm and 132 mm, respectively. When the pH dropped below 6, the surfactant exhibited rapid defoaming. After six cycles of alternating acid-base environments, it maintained excellent foaming performance, achieving a 5-minute foam height of up to 138 mm. Importantly, it retained its foaming capabilities in formation water solutions with a mineralization degree of 200 g/L.These findings hold significant implications for the development of intelligent environmental response treatments for foam drainage and gas production, enhancing the overall efficiency of drainage and gas production operations.