Teacher Dr Josh Hamilton said the school district voted to fire him after he came out as gay to his students. (Josh Hamilton/ YouTube)

A teacher at a Texas high school has said he was targeted to be fired because he came out as gay to his students, but the school is denying it.

Dr. Josh Hamilton taught professional communications and college readiness at Grapevine High School for three years, and also coached its competitive speech team.

According to the Fort Worth Star-Telegram, it was during a speech coaching session that Hamilton gave his own speech about overcoming adversity and coming out as gay.

He said he was trying to motivate the students, and told NBC: “I was like heck, you guys watched me struggle for years through my own mental health battles, because that what it was, and come out on the other side of that has a happy functioning gay man.”

After he gave the speech, he said he was questioned by school district human resources who asked to see his mobile phone. He handed it over and said he had “nothing to hide”.

The Grapevine-Colleyville Independent School District (GCISD) in Texas then placed Hamilton on paid administrative leave, and said that they planned to fire him, pending a termination hearing.

It claims that he sent inappropriate texts to a student, although it has not provided details and Hamilton says on his website to raise awareness of his situation that “to this day, [he has] never seen a copy of the original compliant”.

According to NBC, the teacher admits that he texted a student who babysat his child, but said that none of the messages were inappropriate and that he believes parents heard about his speech and complained to the school.

Kristin Snively, a spokeswoman for GCISD, told the Fort Worth Star-Telegram in a statement: “To be clear, Mr. Hamilton’s sexual orientation has absolutely nothing to do with the reason Mr. Hamilton has been proposed for termination.

“Mr. Hamilton has been proposed for termination for good cause due to violations of the District’s electronic communications policy, violations of student privacy, failure to follow written directives, and violations of the Texas Educator’s Code of Ethics.

“In GCISD, we hold all employees to high standards for their interactions with our most important people, our students. His conduct is not acceptable for an educator in GCISD.”

Hamilton has set up a GoFundMe page to raise money to pay legal fees to “protect [his] professional reputation”.