Yes, it is absolutely legal to get an ESA letter online.
There are a number of credible online services like MyESALetter.net, that provide authentic ESA letters to ESA owners online. It saves you from the hassle of visiting a therapist or medical health practitioner multiple times.