The more forward your neck is bent, the more the neck muscles that hold your head up are strained and the more they hurt. Working on a computer or using a cell phone a lot makes your neck hurt. Remember to stand and sit up straight. Keep your chin in, your ears just above your shoulders and keep your shoulders back.
If you still have neck pain after changing your posture, or if your pain persists, consult your doctor.