Как я могу сохранить данные формы в другое имя файла для каждой отправки? - PullRequest
0 голосов
/ 05 мая 2011

У меня есть форма, которая отправляет данные по электронной почте и сохраняет их в файл, но я хочу, чтобы они каждый раз сохранялись в другом файле.

Вот мой код:

<?php
    // Contact Form

    // get posted data into local variables
    $EmailFrom = "gmail.com";
    $EmailTo = "mail@gmail.com";
    $Subject = "$Website";
    $Website = Trim(stripslashes($_POST['Website'])); 
    $Title = Trim(stripslashes($_POST['Title'])); 
    $Keywords = Trim(stripslashes($_POST['Keywords'])); 

    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Website: ";
    $Body .= $Website;
    $Body .= "\n";
    $Body .= "Title: ";
    $Body .= $Title;
    $Body .= "\n";
    $Body .= "Keywords: ";
    $Body .= $Keywords;
    $Body .= "\n";

    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    // redirect to success page 
    if ($success){
        $string = '"Website","Title","Keywords"' . PHP_EOL;
        $string .= "\"$Website\",\"$Title\",\"$Keywords\"" . PHP_EOL;
        file_put_contents('formdata.txt', $string); // write file
        print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
    }

    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
?>

1 Ответ

1 голос
/ 05 мая 2011

Вот быстрое решение, которое использует текущее время:

file_put_contents('formdata_' . time() . '.txt', $string); // write file
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...