Thank you for asking. I can understand the distress you are through. Before deciding about the management and diagnosis, it is vital to know and understand that reason behind you being not able to ejaculate inside her. Are you having difficulty to get excited or aroused, is there associated anxiety, or early ejaculation problem, etc. Also one must consider problems of masturbation and problematic pornography use. These these could be the reason for you on not having a problem while masturbating but during sexual intercourse.
Next Steps
I would strongly advice you to consult with a sexologist. For more suggestions and specific advices on sexual health, healthy masturbation technique and pornography use, etc you can also consult with me directly here on practo.