This could be a bit tricky to figure out...
To write a log file, your web server will need to have write access to some file on your server. Then you can use a logging function like this...i tries to open the file and if it can't then it tries to change the permissions and open it again. Keep in mind that flash has no idea what to do when the script it's visiting just dies with an error message.
define('LOG_FILE', '/path/to/log.txt'); // this needs to be the file system path to your log file
function log_it($msg_to_log) {
if (!($fd = fopen(LOG_FILE, "a"))) {
$tmparr = posix_getpwnam(CONST_SERVER_USER);
$server_uid = $tmparr['uid'];
chown(LOG_FILE, $server_uid);
chmod(LOG_FILE, 0775);
if (!($fd = fopen(LOG_FILE, "a"))) {
die("Could not open debug file. Mesg was: $msg_to_log");
}
}
if (!fwrite($fd, $msg_to_log . "\n")) {
die("LOG WRITE FAILED!");
}
fclose($fd);
if (filesize(LOG_FILE) == 0) {
/* Something went wrong! */
die("LOG WRITE FAILED FILESIZE IS 0");
}
}
If the log file lives in your web root then yes you can visit it just by visiting the file in a web browser. A web browser should interpret the file as a text file if it ends in ".txt" - at least Firefox does on my Win XP machine. This means that when I write a string with newline characters in it to my log, when I visit the log I actually see the text displayed on separate lines. If you mistakenly called your log file 'log.html' then your browser would render it as html and the line returns just look like a space. Does that make sense?
Another thing to consider is that notepad on a windows machine will only show newline characters if there is a \r AND ALSO A \n character. This is kind of a weird thing. I'm not sure what the historical reason is, but I seem to recall a unix newline char is \n and for some reason these don't get rendered as new lines in windows. Why? Wish I knew. It may be that flash is just interpreting new lines as \n (which corresponds to an ASCII code of 10) and these aren't a 'complete' line return to a windows machine. It may be that your mail client requires both the \r and the \n to show a new line. \r corresponds to ascii code 13.
In order to find out exactly what ASCII codes are in the string that gets submitted, you have to write a separate function which converts each char in a string to its ASCII code so you can see what is really going on. Something like this:
$str = "foobar\r\n";
$max = strlen($str);
echo 'max:' . $max . '<br>';
for($i=0; $i<$max; $i++) {
$char = substr($str, $i, 1);
echo $char .' = ' . ord($str[$i]) . '<br>';
}
As you can see when you run that script, \r and \n are whitespace chars so they don't show up but you still get the '= 13' and '= 10'.
I hope that's helpful.