No, Shakespeare did not say life is but a dream. This phrase actually comes from a poem by Sir Edward Dyer called My Dream. In the poem, Dyer reflects on his life and how it has passed by so quickly. He compares life to a dream and how we are all just passing through this world. While Shakespeare did not originate this phrase, he did use it in his play Henry IV, Part II. In the play, Prince Hal says to his father:
Life is but a walking shadow, a poor player
That struts and frets his hour upon the stage
And then is heard no more. It is a tale
Told by an idiot, full of sound and fury,
Signifying nothing.
In this passage, Prince Hal is reflecting on the futility of life and how everything eventually comes to an end. He compares life to a play where we are all just temporary players on the stage. While Shakespeare didn't say life is but a dream, he does present it as being somewhat meaningless in comparison to eternity.