The star formation history of galaxies: The role of galaxy mass, morphology and environment