Dipole-dipole interaction in cavity QED: The weak-coupling, nondegenerate regime