Have you tried another cable? You should also look closely at the connector on your phone as it might be dirty (pocket fuzz, lint, etc.) You can usually clean the connector with a toothpick or try blowing compressed air (at a distance, not directly) into the connector.
I just had that happen to me the other day. Close out iTunes shut down and restart iMac. Also make sure your energy saver is not set to shutdown. I did all of that and it worked!