A man who sent graphic sexual messages to what he thought was a 14-year-old girl has been given a suspended prison sentence.