- 10 updates
Robert Riley regarded Twitter as a chance to engage in "social banter" but had "no idea" of the site's "vastness", magistrates in Swansea heard.
Riley's solicitor, Giles Hayes, said his client - a former bus driver who left school aged 15 with no qualifications - lived an insular life.
The court also heard a report from the Probation Service saying that Riley was a full-time carer for a 44-year-old woman.
"Because of this he has very little time for social activity out of the house," it said.
Mr Hayes described the tweet about Leeds teacher Ann Maguire as "a senseless act at a very sensitive time."
Magistrates were told that, since his arrest, Riley has sought help from counsellors over anger management issues.
His legal team admitted while his offensive comments pushed Riley past the custody threshold, the court could still impose a suspended sentence.
Mr Hayes said that would give the defendant the chance and the support to address his behavioural problems.
However, magistrates decided otherwise and Riley - dressed in a black shirt and trousers - was led down to the cells by two female security officers.
He hid his face as he was then led into a custody van and driven to prison.
Prosecutor Linda Baker told the court that following a complaint to police, other offensive tweets by Robert Riley came to light.
Among them were messages about the missing Malaysian plane, the Korean ferry disaster and champion tennis player Serena Williams.
Despite widespread shock at the death of Leeds schoolteacher Ann Maguire, magistrates in Swansea heard Robert Riley saw fit to make fun of the tragedy online two days later.
Despite a backlash from other Twitter users horrified by his messages, the 42-year-old remained incredulous, saying: "Of all the sick things I've tweeted, starvation, genocide, rape and torture, it's the teacher from Leeds that outrages everyone the most."
During Robert Riley's sentencing, chairwoman of the bench Georgina Scannell voiced her disgust at his "vile" and "offensive" online messages.
Swansea magistrates said Robert Riley's online messages were also racially and religiously aggravated and that only a custodial sentence could be imposed.
Riley, from Port Talbot, was sentenced to eight weeks in custody after admitting posting an abusive Twitter message about the death of Leeds schoolteacher Ann Maguire.
The 42-year-old was the second person to be charged with the offence in the wake of the death of Mrs Maguire, who was stabbed to death in her classroom at Corpus Christi Catholic College last month.
Yesterday a third person was arrested in Cardiff and bailed.
Robert Riley, 42, who admitted posting offensive messages on Twitter about stabbed teacher Ann Maguire, has been jailed for eight weeks at Swansea Magistrates' Court.
Robert Riley, from Port Talbot, is due to be sentenced today by magistrates in Swansea after admitting posting an offensive message on Twitter.
The message referred to the death of Leeds school teacher Ann Maguire, who was stabbed to death in front of pupils at Corpus Christi Catholic College last week.
During an earlier hearing his solicitor Michael Walsh said: "He is mortified by his own behaviour and he apologises for any upset that may have been caused to everybody."
A man has admitted sending a message of a grossly offensive, abusive or malicious character after the murder of Leeds teacher Ann Maguire.
Robert Riley, from Port Talbot, South Wales, was granted bail and will be sentenced at Swansea Magistrates' Court.
The messages were not read out in court but the bench heard that some of them related to the murder of Mrs Maguire, 61, at Corpus Christi Catholic College in Leeds a week ago.
Riley left court saying nothing, with his grey tracksuit top pulled over his head.
During the 10-minute hearing his solicitor Michael Walsh said: "He is mortified by his own behaviour and he apologises for any upset that may have been caused to everybody."
Mr Walsh asked the magistrates to free his client on bail, telling them the only reason he had been held overnight was for his own safety.
He suggested that Riley may be in more danger in a Leeds prison than he would be walking the streets.
Earlier, Sandra White, prosecuting, told the court that Riley had posted a number of offensive tweets, only some of which related to the murder of Mrs Maguire.
She said the offence had come to the attention of West Yorkshire Police because of this connection but told the bench that it should properly have been charged in South Wales.
Ms White said the magistrates in Swansea would also be in a position to deal with Riley's existing community order. No details of this order were given in court today.
Riley was given bail on condition that he does not use social networking sites and the internet generally between now and his appearance on Thursday.
The defendant sat in the dock with a woman security officer, wearing his track suit top over a grey T-shirt and blue jogging bottoms.
A 42-year-old man from Port Talbot has admitted posting abusive Twitter messages about the death of school teacher Ann Maguire.
Robert Riley appeared before magistrates in Leeds today where he admitted sending a message of a grossly offensive, abusive or malicious character.
Mr Riley has been granted bail and is due to be sentenced at Swansea Magistrates' Court on Thursday.
He was the second person to be charged with the offence in the wake of the death of Mrs Maguire, who was stabbed to death in her classroom at Corpus Christi Catholic College in Leeds, a week ago.
A 42-year-old man from Port Talbot has been arrested by police over allegations of malicious communications after the death of Leeds teacher Ann Maguire.
West Yorkshire Police say the man remains in custody.
On Saturday, a 21-year-old man from Leeds was charged with malicious communications following Mrs Maguire's death on Monday.