He admitted causing or inciting a child to engage in sexual activity while he was in a position of authority between September 1 and November 17, 2015.
In mitigation, Patricia Doherty said that Stirling had recognised his actions had been "incredibly foolish", adding that there had been no physical contact with the girl.
"He had some problems of his own in the past and foolishly and naively thought that he could help her," she added.
"He resigned and got himself another job as a receptionist at a hotel in Derbyshire.
"He knows that he can't go back into teaching at all. He has taken this job because it keeps him away from youngsters. He has put distance between himself and the girl."
Doherty said that the girl was close to turning 18, adding that had the messages been sent a few weeks later, Stirling's life "would not have been ruined".
However, Recorder Eric Elliott QC told Stirling that his actions amounted to a "significant breach of trust" and should have known not "to go down that road".
"She was having certain personal and domestic problems and looked to you to help her. You, very misguidedly and perhaps naively, thought you could help her," he added.
"You knew full well, bearing in mind you were a teacher in a position of trust, that you ought not to go down that road.
"It emerged that you had been involved in this activity. It's a significant breach of trust. You have cut off all contact with her and moved away from the area."
Elliott instructed that Stirling attend a rehabilitation centre and be registered on the sex offenders list for a total of five years.