Ciao. Prova a sostituire "$messaggio=mysql_real_escape_string ($messaggio)" con:
Codice PHP:
if (get_magic_quotes_gpc())
    
$messaggio stripslashes ($messaggio);
$messaggio mysql_real_escape_string ($messaggio);