Hamels (10-3) limited the Rockies to two runs on six hits and three walks over eight innings. The left-hander struck out seven while placing 73 of his 113 pitches for strikes.
Mayberry's two-run blast in the fourth inning broke a 1-1 tie and put the Phillies ahead to stay.
Carlos Ruiz went 2-for-4 with a two-run homer and three RBI as Philadelphia improved to 5-12 in June, taking the opener of a three-game series at Citizens Bank Park.
Josh Outman (0-3) surrendered four runs on five hits over 4 1/3 innings for the Rockies.
Colorado got RBI from Tyler Colvin and Chris Nelson in the loss.
Celebrity Breakups and divorces of 2014 [PHOTOS]