A phase-only hologram applies a modal transformation to an optical transverse spatial mode via phase encoding and intensity masking. Accurate control of the optical field crucially depends on the method employed to encode the hologram. In this Letter, we present a method to encode the amplitude and the phase of an optical field into a phase-only hologram, which allows the exact control of spatial transverse modes. Any intensity masking method modulates the amplitude and alters the phase of the optical field. Our method consists in correcting for this unwanted phase alteration by modifying the phase encryption accordingly. We experimentally verify the accuracy of our method by applying it to the generation and detection of transverse spatial modes in mutually unbiased bases of dimension two and three.