A photoelectric sensor that has at least one of a light projecting section that emits light to a front space and a light receiving section that receives light from a front zone, the photoelectric sensor comprising: a case body with a substantially rectangular parallelepiped shape that accommodates at least one of the light projecting section and the light receiving section, wherein the case body comprises: a front surface that has a light projecting and receiving surface that allows at least one of the light from the light projecting section and the light to the light receiving section to pass therethrough; a rear surface that is located on a side opposite to the front surface; a top surface that connects the rear surface to the front surface; a bottom surface that is located on a side opposite the top surface and connects the rear surface to the front surface; and two side surfaces (25, 26) that are located opposite each other, each of the two side surfaces (25, 26) connects the rear surface to the front surface and connects the top surface to the bottom surface; wherein the front surface and the rear surface are longer in an up-down direction than in a left-right direction, and the top surface and the bottom surface are longer in a front-rear direction than in the left-right direction; at least one of the light projecting section and the light receiving section is connected to a cord via a control section; and a cable that accommodates the cord is attached to the rear surface, wherein the case body further accommodates a substrate on which the light projecting section and the light receiving section are mounted and a portion (50a, 50b) of the cord that is not covered with the cable, the photoelectric sensor being characterized in that: the side surfaces (25, 26) are longer in the up-down direction than in the front-rear direction, a plurality of attachment sections for securing the case body to an outside are provided on the rear surface, the cable is attached between the attachment section that is located on an upper side on the rear surface and the attachment section that is located on a lower side on the rear surface, and the attachment sections have protruding shapes toward the rear side beyond a portion of the rear surface to which the cable is attached, wherein the portion of the rear surface to which the cable is attached has a shape that is recessed toward the front side beyond the attachment sections. a case body with a substantially rectangular parallelepiped shape that accommodates at least one of the light projecting section and the light receiving section, wherein the case body comprises: a front surface that has a light projecting and receiving surface that allows at least one of the light from the light projecting section and the light to the light receiving section to pass therethrough; a rear surface that is located on a side opposite to the front surface; a top surface that connects the rear surface to the front surface; a bottom surface that is located on a side opposite the top surface and connects the rear surface to the front surface; and two side surfaces (25, 26) that are located opposite each other, each of the two side surfaces (25, 26) connects the rear surface to the front surface and connects the top surface to the bottom surface; wherein the front surface and the rear surface are longer in an up-down direction than in a left-right direction, and the top surface and the bottom surface are longer in a front-rear direction than in the left-right direction; a front surface that has a light projecting and receiving surface that allows at least one of the light from the light projecting section and the light to the light receiving section to pass therethrough; a rear surface that is located on a side opposite to the front surface; a top surface that connects the rear surface to the front surface; a bottom surface that is located on a side opposite the top surface and connects the rear surface to the front surface; and two side surfaces (25, 26) that are located opposite each other, each of the two side surfaces (25, 26) connects the rear surface to the front surface and connects the top surface to the bottom surface; wherein the front surface and the rear surface are longer in an up-down direction than in a left-right direction, and the top surface and the bottom surface are longer in a front-rear direction than in the left-right direction; at least one of the light projecting section and the light receiving section is connected to a cord via a control section; and a cable that accommodates the cord is attached to the rear surface, wherein the case body further accommodates a substrate on which the light projecting section and the light receiving section are mounted and a portion (50a, 50b) of the cord that is not covered with the cable, the photoelectric sensor being characterized in that: the side surfaces (25, 26) are longer in the up-down direction than in the front-rear direction, a plurality of attachment sections for securing the case body to an outside are provided on the rear surface, the cable is attached between the attachment section that is located on an upper side on the rear surface and the attachment section that is located on a lower side on the rear surface, and the attachment sections have protruding shapes toward the rear side beyond a portion of the rear surface to which the cable is attached, wherein the portion of the rear surface to which the cable is attached has a shape that is recessed toward the front side beyond the attachment sections.