Any variation of the fundamental physical constants, and more particularly of the fine structure constant, $alpha$, or of the mass of the electron, $m_e$, would affect the recombination history of the Universe and cause an imprint on the cosmic microwave background angular power spectra. We show that the Planck data allow one to improve the constraint on the time variation of the fine structure constant at redshift $zsim 10^3$ by about a factor of 5 compared to WMAP data, as well as to break the degeneracy with the Hubble constant, $H_0$. In addition to $alpha$, we can set a constraint on the variation of the mass of the electron, $m_{rm e}$, and on the simultaneous variation of the two constants. We examine in detail the degeneracies between fundamental constants and the cosmological parameters, in order to compare the limits obtained from Planck and WMAP and to determine the constraining power gained by including other cosmological probes. We conclude that independent time variations of the fine structure constant and of the mass of the electron are constrained by Planck to ${Deltaalpha}/{alpha}= (3.6pm 3.7)times10^{-3}$ and ${Delta m_{rm e}}/{m_{rm e}}= (4 pm 11)times10^{-3}$ at the 68% confidence level. We also investigate the possibility of a spatial variation of the fine structure constant. The relative amplitude of a dipolar spatial variation of $alpha$ (corresponding to a gradient across our Hubble volume) is constrained to be $deltaalpha/alpha=(-2.4pm 3.7)times 10^{-2}$.