I know this can get a bit confusing, so let me try to explain it, at least as the terms are used in North America.
The title "Doctor" and the abbreviated prefix "Dr." come from the Latin for "teacher", and are traditionally bestowed on those who have earned the highest academic degree attainable. The suffix Ph.D. is an abbreviation for Philosophiæ Doctor (L. "Teacher of philosophy"), with "philosophy" from the Greek for "love or pursuit of wisdom". The Ph.D. is awarded in most academic disciplines, including science. Medical professionals may also hold the title "Doctor" even though they may do little or no teaching, with common degrees being M.D. (Medicinae Doctor, or Doctor of Medicine), D.V.M. (Doctor of Veterinary Medicine), D.D.S. (Doctor of Dental Surgery), and so on.
As a noun rather than a prefix, "Doctor" is usually reserved for medical doctors ("I'm not a doctor but I play one on TV"). Usually, the person teaching your course at a major universitiy is a "Professor" and not a "Doctor" (noun) ("Are you really a mad scientist, professor?"). He or she does, however, use the prefix "Dr.". Get it?
To make it more complex and Monty Python-ish, the prefix "Prof." is not used by all professors. "Professor" (noun) is the position, but there are also ranks. In North America, these would be "Assistant Professor", "Associate Professor", and "Professor" (or "Full Professor"). In many cases, only full professors use the prefix "Prof." in situations outside the university. I don't use "Prof. Gregory" in non-university settings because I am not a full professor. However, I am a professor, not a doctor, although I use Dr. Gregory instead of Prof. Gregory. Right.
Perhaps that's all too complicated to bother about. Here is the short version: When addressing a professor*, just go with "Dear Dr. So-and-so" unless he or she asks you to call him or her something different.
(*To clarify, this post is mostly for students)