You're using it like a NPN follower, the mosfets work with voltage, not current.
All the voltage will drop in the led and resistor, and the mosfet will barely turn on if it does at all.
This is the way :
If you're keeping the LED, I'd put it to be driven by the mosfet too.
ELS817 has VF = 1.2 , you can drive it directly with the digital pin.
5mA is enough for CTR=1:
It's just for low frequency signals, right? Datasheet shows 4/3uS rising/falling time, and up to 18uS.
You can save power by rising R1 value, ex. 1K, it will have slower response / higher rising time, but for something simple like powering a relay and such, it's perfectly OK.
(I put 3.3V, but whatever it uses).