Re: Send text file contents by e-mail

From: Date: Mon, 07 Aug 2000 01:53:57 +0000
Subject: Re: Send text file contents by e-mail
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10394@lists.php.net to get a copy of this message
On 6 Aug, Martin E. Koss wrote: > I'm trying to send the contents of a text file by e-mail and then replace > the file with new content: Here is the code so far, that is not quite > working: > > $fd = fopen( $filename, "a+" ); > $contents = fread( $fd, filesize( $filename ) ); > // Send the e-mail > mail($mek, "Status log", $contents, > "From: $mek"); > > // now replace file contents with the start line for today > $StartLine = "Date Time Emails Server"; > fputs($fd,$StartLine); > fclose($fd); > } > > Any ideas why? > Martin > It looks like you are appending to the existing file there. After reading the file, you should close the file and then fopen($filename, "w") to truncate the file to zero length, or create it if it doesn't exist. Then you can write the new data to an emoty file. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#10394) next »