У меня есть форма, которая отправляет данные по электронной почте и сохраняет их в файл, но я хочу, чтобы они каждый раз сохранялись в другом файле.
Вот мой код:
<?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\">";
}
?>