A measurement is presented for the electroweak production of a Formula Presented boson, a photon (Formula Presented), and two jets (j) in proton-proton collisions. The leptonic decay of the Formula Presented boson is selected by requiring one identified electron or muon and large missing transverse momentum. The two jets are required to have large invariant dijet mass and large separation in pseudorapidity. The measurement is performed with the data collected by the CMS detector at a center-of-mass energy of Formula Presented, corresponding to an integrated luminosity of Formula Presented. The cross section for the electroweak Formula Presented production is Formula Presented, whereas the total cross section for Formula Presented production is Formula Presented. Differential cross sections are also measured with the distributions unfolded to the particle level. All results are in agreement with the standard model expectations. Constraints are placed on anomalous quartic gauge couplings (aQGCs) in terms of dimension-8 effective field theory operators. These are the most stringent limits to date on the aQGCs parameters Formula Presented and Formula Presented.