Forum Moderators: coopster

Message Too Old, No Replies

Write to text file

         

phpdude

10:35 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



Hi PHP Group,

I've got a PHP form processor running that sends the forms fields via email and then writes the email address of the sender to a text file on the server.

I've got it working perfectly except when it writes the email address to the text file, it puts them all on the same line. I need to get it to put each address on the next line down. This is probably a pretty simple thing to do but my eyes are bugging after trying for a while now.

If anyone could help, it would be appreciated.

Here is the code that writes to the text file:

////////////write to file///////////
$out = fopen("/home/myserver/leads.txt","a");

if (!$out) {
print("Could not append to file");
exit;
}

$T1 = $_POST[$reply_to_field];

fwrite($out,"$T1\t");

fclose($out);

phpdude

10:53 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



Boy, it's the little things that drive you nuts. I was missing \n for fwrite.

So, the line looks like this now:

fwrite($out,"\n$T1\t");

Works like a champ!

lazydog

8:19 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



Hi!

You could also just use this one liner -
error_log($email."\n", 3, "/home/myserver/leads.txt");

It is usually used for recording erros, but hey, who says we can't use it for something else ;-)

Saurabh.