Hi, im making the website for a local youth club, and the leader there, wants to have comments posted automatically, under the contact box.
I'm fine with the contact form, that works fine. Its the same one used on my website, its been tested by 3 other people to. The redirection works fine too. I want to know how to send the results to a .txt file, so I can include them under the form.
<?php /* Subject and Email variables */ $emailSubject = 'Online Contact Form'; $webMaster = 'info@pauldavis.org.uk'; /* Gathering data variables */ $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; $body = <<<EOD <hr> Name: $name Email: $email Comments: $comments EOD; s $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results renderes as HTML */ $theResults = <<<EOD <html> <head> <title>Your Page Title</title> <meta http-equiv="REFRESH"content="0;url=http://www.wainscottyouthclub.org.uk"></HEAD> <BODY> Your message was sent successfully. You should be automaticly redirected to the home page. It not, click <a href="http://www.wainscottyouthclub.org.uk" target="_self">here</a>. </BODY> </HTML> EOD; echo"$theResults"; ?>Any help greatly appreciated!
Is the results what the user entered into the contact form?
Anyway, to read and write to files see:
fopen - http://www.php.net/manual/en/function.fopen.php
fwrite - http://www.php.net/manual/en/function.fwrite.php
fread - http://www.php.net/manual/en/function.fread.php
You can also use the "shortcuts":
file_get_contents() and file_put_contents(). The latter being only available in PHP5 but you can easily emulate it in PHP4.
eg:
if (!function_exists('file_put_contents')) {
function file_put_contents($file, $content, $flags = null, $context = null) {
// code here... etc...
}
}