How can this happen

I am in my 2nd trimester of pregnancy my boyfriend and i have been together 4 yrs i went for a check at my ob appt and they tell i have an sti i have not been with anybody else he says sorry he loves me then says he hasnt been with anyone now how would i get it?