Now per QED, electrical charges interactions are effected by photons. Suppose you are one of the two charges. How do you know to attract or repel the other charge? In other words, how do you know if the other charge is the same or opposite, since the critical interface you have with it is the zero-charged photon? It would seem that the photon would need to convey to the charges their relative polarity. How does the photon do that?
Now per QED, electrical charges interactions are effected by photons. Suppose you are one of the two charges. How do you know to attract or repel the other charge?
You want something that does not exist - intuitive picture of physical process within a theory which is a demonstration of how far can one go with mathematisation of experience and ignoring intuitive pictures.
To study quantum electrodynamics you have to concentrate on its computational algorithms and neglect intuitive pictures, to study intuitive pictures you have to neglect QED.
Both are a good thing to study, just do not expect it is easy to make them consistent.
Since the field of each charged particle extends to infinity, the fields of two particles are "in contact" with each other (no "communication" is necessary). When the charges are not equal (+ & -), the fields "cancel" each other along the line connecting their centers. This causes the attraction of the particles. When the charges are the same (+ & + ; and - & -), the fields reinforce each other causing the particles to repel each other.
The attraction of unlike charges and the repulsion of like charges is an experimental observation that has to be included in any model of electromagnetic reactions
When talking of photons one is in the quantum mechanical regime.
As in classical electrodynamics the sign of the charge defines the potential, attractive or repulsive, between the two charges, so in the quantum mechanical formulations the potential carries the charge , whether it is an attractive or repulsive potential. The solutions which are the state function of the system carry this information, and this is the way that the two particles "know" the charge of each other.
Carrying the information quantum mechanically means that if a scattering experiment is performed there will be a region in phase space where the attractive potential solutions will differ from the repulsive ones. One can get an intuition on this from simple quantum mechanical potentials , for example in these lecture notes in the figures on page 30 how there are parameter regions where the attraction and repulsion solutions diverge. Of course attractive situations also allow for bound states, which is another story.
When the distances are very large , the behavior is similar, so in this sense the two particles will "know" the charge of each other only close to each other.
For a quantum field theory description of virtual particle exchanges between positive and negative , negative and negative have a look at this entry, figures 1 and 2.
The bottom line is that the observed behavior of charges is accommodated by the mathematical models in all frameworks, classical and quantum.