I'm just trying to quantize the electromagnetic field. It has four independent components, where two of them are physical and belong to the (transverse) polarization. But why does it not have a longitudinal component. Is it because photons are massless?
Yes, because photons are massless. A 4-vector describing a photon gauge field has initially 4 degrees of freedom. Temporal degree of freedom is fictitious, because it (edit: its time derivative) does not appear in the kinetic term of the Lagrangian (thus it does not propagate). Then, you can fix gauge symmetry (say, $\partial_\mu A^\mu=0$) to eliminate one other d.o.f. The two that are left are the transverse ones. You can check this by using the Lorentz gauge $\partial_\mu A^\mu=0$ in momentum space: $k_\mu A^\mu=0$. Since there is no rest frame, you can only choose your frame so that the photon moves, say along the $x$ ($\mu=1$) axis. That means $k_\mu=(-E,E,0,0)$ and from the Lorentz condition we have $-EA^0+EA^1=0$. Thus, longitudinal mode is fictitious too.