Several things need attention here:
if (file_exists("mail.txt"))
{
$fi=fopen("tmp/mail.txt","a");
(1) Note you're not talking about the same file in both calls. The first
asks whether 'mail.txt' exists in the current directory, whereas
the second opens a file in 'tmp' under the current directory.
(2) Do you really mean 'tmp' under the current directory, rather than
'/tmp'?
(3) The test itself is completely unnecessary: fopen(...,"a") will create
the file if it doesn't exist.
$fi=fopen("tmp/mail.txt","a");
fputs($fi,$user);
(4) This is very dangerous program design. Always check the return
value of fopen() to see if it succeeded or not.
(5) The underlying problem, once you've straightened out exactly which
directory you're wanting to create the file in, is that you (or, rather, the
user under which PHP runs (usually 'nobody' in the case of Apache, but
if it's a shared virtual server that might be different) doesn't have rights
to create files in that directory.