A new mechanism for the internal heating of ultra-short-period planets is proposed based on the gravitational perturbation by a non-axisymmetric quadrupole moment of their host stars. Such a quadrupole is due to the magnetic flux tubes in the stellar convection zone, unevenly distributed in longitude and persisting for many stellar rotations as observed in young late-type stars. The rotation period of the host star evolves from its shortest value on the zero-age main sequence to longer periods due to the loss of angular momentum through a magnetized wind. If the stellar rotation period comes close to twice the orbital period of the planet, the quadrupole leads to a spin-orbit resonance that excites oscillations of the star-planet separation. As a consequence, a strong tidal dissipation is produced inside the planet. We illustrate the operation of the mechanism by modeling the evolution of the stellar rotation and of the innermost planetary orbit in the cases of CoRoT-7, Kepler-78, and K2-141 whose present orbital periods range between 0.28 and 0.85 days. If the spin-orbit resonance occurs, the maximum power dissipated inside the planets ranges between $10^{18}$ and $10^{19}$ W, while the total dissipated energy is of the order of $10^{30}-10^{32}$ J over a time interval as short as $(1-4.5) times 10^{4}$ yr. Such a huge heating over a so short time interval produces a complete melting of the planetary interiors and may shut off their hydromagnetic dynamos. These may initiate a successive phase of intense internal heating owing to unipolar magnetic star-planet interactions and affect the composition and the escape of their atmospheres, producing effects that could be observable during the entire lifetime of the planets [abridged abstract].