You are going to have to do an awful lot of reading, beyond just SME forums. The biggest problem with SIP is if you get it wrong, the bills can be big.....
SIP phones are not as simple as people like to make out. SIP, RTP & NAT are not the best of bed fellows.
So, you need to go and read about SIP and RTP ports for starters, in general terms. There is mountains of stuff out there.
Customer firewall must allow SIP and RTP to allow SIP devices to place and receive calls
You may want to look at one or more of the following:
TCPPorts=5061
UDPPorts=5060,5061,5160,5161,4569,10000:20000
SIP is usually UDP 5060 and RTP on UDP 10000-20000 but YMMV...
SME should let those ports out as far as I am aware though.
So...
When the IP phones are connected directly to the router and bypassing the server its able to register itself with the provider server on the internet.
Hmmmm.
It sounds like the ISPs router is blocking the required ports so it can handle them itself (at a guess)??
So how is your SME configured with the router/broadband? Can you be a bit explicit here - diagrams if necessary !!
You say it is in gateway mode, but how does that work with the router? Do you normally use some form of modem with SME, or a ethernet connection? Or is SME in gateway mode behind the router?