A father-of-two has been sentenced for sending explicit messages to a 14-year-old child who was actually an undercover police officer.