if(mysql_result(mysql_query(\"SELECT COUNT(*) FROM `mail` WHERE `user_1` = \'\".$user[\'id\'].\"\' AND `user_2` = \'\".$ank[\'id\'].\"\' OR `user_1` = \'\".$ank[\'id\'].\"\' AND `user_2` = \'\".$user[\'id\'].\"\'\"
,0)==0){
mysql_query(\"INSERT INTO `mail` (`user_1`, `user_2`, `time`) VALUES (\'\".$user[\'id\'].\"\', \'\".$ank[\'id\'].\"\', \'\".time().\"\')\"
;
}else{
mysql_query(\"UPDATE `mail` SET `time` = \'\".time().\"\' WHERE `user_1` = \'\".$user[\'id\'].\"\' AND `user_2` = \'\".$ank[\'id\'].\"\' OR `user_1` = \'\".$ank[\'id\'].\"\' AND `user_2` = \'\".$user[\'id\'].\"\' LIMIT 1\"
;
}
mysql_query(\"INSERT INTO `mail_msg` (`user_1`, `user_2`, `msg`, `time`) VALUES (\'\".$user[\'id\'].\"\', \'\".$ank[\'id\'].\"\', \'\".mysql_real_escape_string($_POST[\'msg\']).\"\', \'\".time().\"\')\"
;
После этого добавь:
header(\'location: ?name=\'.$ank[\'login\']);