Based on the data of A-share listed enterprises in China from 2006 to 2020, this paper examines the impact of corporate digital transformation on corporate environmental social responsibility and its mechanism. It is found that the digital transformation of enterprises has a significant positive impact on the environmental social responsibility of "source control" and a significant negative impact on the environmental social responsibility of "end-governance", and realizes the transformation from "end-governance" to "source control". "The empirical findings are based on a series of robust tests. The empirical findings still hold after a series of robustness tests and endogeneity treatments. The mechanism analysis finds that digital transformation affects two types of corporate environmental social responsibility through employee green behavior, corporate environmental concern and total factor productivity. The moderating effect finds that corporate governance and financing cost can further moderate the impact of digital transformation on both types of environmental social responsibility. Heterogeneity analysis finds that digital transformation has a more significant impact on non-state, high environmental regulation and highly educated executives in taking "control at source" environmental social responsibility. Motivation analysis reveals that the shift from "end-of-pipe" to "source-control" CSR is motivated by the more significant positive impact of the latter on corporate value, which is further reinforced by digital transformation.