Generally heat is used to relieve muscle spasm associated with neck or back pain. The muscle spasm is a response to the pain caused from injury to deeper structures such as a pinched joint, nerve or “slipped disc”.
The pain origin is too deep to be effected by heat (or ice) and therefore heat is relieving the symptoms.
Your heat should only ever be mild and comfortable as this will provide relief without burning.
An ice pack is best used for acute, near surface injuries, such as shoulders, knees and ankles. Ice is particularly effective for the reduction of inflammation and swelling which may actually cause more collateral damage to other tissues not injured. (ligaments or tendons). Another benefit from ice is temporary pain reduction from its numbing effect. Care should be taken when applying ice to avoid being too cold for too long as this can result in “ice burn”.