This study aims to comprehensively examine the effects of different types of Internet use and happiness while considering the mediating role of environmental quality perception and the moderating role of a sense of environmental security. Drawing on the uses and gratifications theory, negativity bias, and social cognitive theory, the study investigates the mediating role of environmental quality perception and the moderating role of environmental security in the above relationship. Using data from 3162 respondents in the 2021 Chinese Social Survey (CSS) and Structural Equation Modeling (SEM), the study finds that Internet use for information and educational purposes significantly enhances happiness, with environmental quality perception acting as a mediator. Moreover, a moderating effect of environmental security was observed in the relationship between Internet use for educational purposes and national environmental quality perception. Specifically, the interaction between study-related Internet use and the sense of environmental security significantly and positively predicted national environmental quality perception. These findings highlight the complex interaction between Internet use, environmental factors, and happiness, offering insights into policy interventions aimed at improving Internet access and environmental awareness to enhance public mental health outcomes in China.