PC817 input features
In the reverse direction, no current would flow through the diode (initially), so there would be no voltage dropped over the resistor, so the IR&nbsp;LED in the PC817 would see the whole voltage of 325&nbsp;V&nbsp;(DC). The PC817 has a reverse voltage rating (VR) of 6&nbsp;V, so it would blow up.

You could instead use the PC814, which has similar characteristics, but an AC input with two antiparallel LEDs:



Alternatively, just put a&nbsp;diode like that in the front of the PC817. (Then the output of the PC817 would switch on only every second half wave.)