While I agree with the ideas below that there is possibly a power struggle over toileting (is he defiant or at least stubborn with you about other things too? If so, this could be part of that defiance)....
And I also agree that there may be emotional issues going on as well (are there changes/problems at home--new sibling, sibling with issues who gets lots of attention, stress between parents, or issues at school?)....
I want to say very loudly and clearly:
Please get him to a doctor first, foremost and immediately.
He may not be defiant or resistant or ornery or even having any emotional issues -- he may have a real, physical issue. Some kids lack the physical abiility to feel the urge to "go." They are not being willful; they genuinely cannot control their bodies like we assume they can. Please get any physical issues ruled out now, and don't wait. If your son has actually been having a physical problem but you have been treating it with discipline as a behavioral issue, you will need to change how you handle this instantly or it is going to leave him resentful and even more resistant -- and it won't do a thing to help him get to the toilet on time, either.
Once you rule out a medical problem (and it may take several visits, trip to a specialist pediatric urologist, etc., tests like ultrasounds, etc. so get your patience ready), then look at what to do next. You will need to be willing to pick apart your own lives to see whether there are stresses that make him so unconcerned about how he smells or how other kids react that he lets this happen. But again, that is only IF he "lets" this happen -- find out first if there is something medical going on and proceed from there. You very well may need to have him see a counselor and you might need family counseling as well, if this is a part of a larger issue. If he does not have a physical issue, it's clear that your discipline is not reaching him and you need some professional help to find out what will reach him, because a child his age in school is going to very soon have some serious issues and be taken out of activities and school if he cannot control pee and poop.
Meanwhile, please do not say that "kids won't want to go near you for fear you'll pee on them." That did not work so far, and is not going to work if you keep saying it. But it will be something he remembers and he will remember it as "mom thinks I smell and nobody likes me so why bother to be clean?" A counselor could give you other tactics to use with him that could work better -- after you rule out medical issues.