This quotation is attributed to Einstein’s letter of 1950, as quoted in The New York Times (29 March 1972) and The New York Post (28 November 1972). However, The New Quotable Einstein by Alice Calaprice (Princeton University Press, 2005: ISBN 0691120749), p. 206, has a presumably more accurate version of this letter, which she dates to February 12, 1950 and describes as "a letter to a distraught father who had lost his young son and had asked Einstein for some comforting words:
“A human being is a part of the whole, called by us ‘Universe,’ a part limited in time and space. He experiences himself, his thoughts and feelings as something separate from the rest — a kind of optical delusion of his consciousness. The striving to free oneself from this delusion is the one issue of true religion. Not to nourish it but to try to overcome it is the way to reach the attainable measure of peace of mind." The other quote is apparently the melding of two Einstein quotes.