On my illustration :
Left circuit shows NO - When given contact in sensor You will get conduction in output of optocoupler.
Right circuit shows NC - When connections is lost (opened), on output from optocoupler You will get contact. Its NC to NO conversion.
If You look better on right circuit You can use also NO to NC. If sensor is NO on output of optocoupler You always get contact (NC), if on sensor give contact situation is changed on output of optocoupler You get NO!
I edit picture for better explaining, here it is :
View attachment 63168
For 12V use 10K between plus pole and transistor base. Transistor may be any small for signal purposes BC546.