Dear Dr. John,
First of all, I would like to thank you for your dedication to students like me. My learning experiences in your course have exceeded all my expectations and have inspired me to further advance my academic career. The course I took with you has given me a newfound appreciation for the field of Computer Science and has been instrumental in my desire to pursue the PhD program.
I am writing to you to inquire if it may be possible for you to write me a recommendation letter which is required as part of the application process. You have not only gotten to know me as a student but also on personal level and I believe you understand my strengths well enough to provide useful insights to the admission committee. I hope to use the knowledge and insights gained from the PhD program to inspire future students to major in Computer Science just as your enthusiasm and love for the field has inspired me to pursue further education. Taking your course has significantly expanded my understanding of the field as well as increased its appeal to me.
Please do let me know should you require additional information or may have questions. I understand you have a very busy schedule so please take your time to write the recommendation letter. I may come to the office to pick up the recommendation letter or you could mail to me, whichever is more convenient for you. I once again thank you for your professional dedication to the students and hope your recommendation will go a long way towards helping me getting admission into the PhD program.