PHP:除了电子邮件之外还将表单数据写入文本文件?

I am using the following code to email the results of a form submission. Since I'm running without a database I'd like some sort of other record.

<?php
    $to = "me@me.com"; 
    $from = $_REQUEST['email']; 
    $name = $_REQUEST['name']; 
    $headers = "From: $from"; 
    $subject = "New Message"; 
    $fields = array(); 
    $fields{"first_name"} = "first_name";
    $fields{"last_name"} = "last_name"; 
    $fields{"email"} = "email"; 
    $fields{"phone"} = "phone"; 
    $fields{"hospital"} = "hospital"; 
    $fields{"title"} = "title"; 
    $body = "Here is what was sent:

"; 
    foreach($fields as $a => $b){   
        $body .= sprintf("%20s: %s
",$b,$_REQUEST[$a]); 
    }
    $send = mail($to, $subject, $body, $headers);
?>

How do I save the results to a text file in addition to email? I've seen examples on how to do text but not in addition to email.

you should check the file functions :

An example of what you could do :

$filePath = 'records.txt';
file_put_contents($filePath, "
Your text here...", FILE_APPEND);

Should be something like this:

//Email code here...

if(!$file = fopen('records.txt', 'a+')) {
    echo 'Could not write to file.';
    exit;
}

$content = "Email sent on: " . time() . PHP_EOL . "***" . PHP_EOL . $body . PHP_EOL . "***" . PHP_EOL;

if(fwrite($file, $content) === false) {
    echo 'Could not write to file.';
    exit;
}

fclose($file);

For more see examples at: http://php.net/fwrite