If the charger is certified by Apple, another reason why it's not working could be that it's damaged.
Usually, you get this message when a cable or accessory is not certified by Apple. This feature was introduced with iOS 7, for security reasons. Before, some iPhones using third party cables, caused injuries, even death.
For cables, there's a workaround.
Plug the cable into a wall charger. Then turn off the iPhone. As soon as you see the spinning wheel, plug the cable into your iDevice. The iPhone will turn off completely. Leave it that way for a while, maybe 15 minutes. Then turn it on again, and dismiss the "This cable..." message. It might charge, in spite of the message.
If it's a non-certified accessory, doing this is risking your own security, though.
Another reason, though very unlikely, could be that there's some lint in your iPhone's charging port. Take a look at it, clean the port, and connect the charger once more.
Hope that helps.