forgottenglory Posted September 6, 2007 Share Posted September 6, 2007 I have searched for this on the Net but couldn't come across any tutorials which explains how to do this. I would like to build an anonymous feedback form which would contain only one text field and one submit button. The script must be able to prevent people from submitting a blank form. Could anybody please point me in the direction of a tut that would explain how to do the above? Thanks Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 6, 2007 Share Posted September 6, 2007 What do you want the feedback form to do? email the feedback to you or store it in a database? Quote Link to comment Share on other sites More sharing options...
forgottenglory Posted September 6, 2007 Author Share Posted September 6, 2007 Send to an email address Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 6, 2007 Share Posted September 6, 2007 You can't have searched very hard. http://www.google.com/search?q=email+form+php Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 6, 2007 Share Posted September 6, 2007 Try this <? // Change to your own email address $your_email = "you@yourdomain.com"; // This is what is displayed in the email subject line // Change it if you want $subject = "Message via your contact form"; // This is displayed when the email has been sent $thankyou_message = "<p>Thankyou. Your feedback has been sent.</p>"; $self = $_SERVER['REQUEST_URI']; $message = $_POST['txtMessage']; $send = $_POST['send']; $msg="<p>Please fill in this form if you have any queries or suggestions.</p>"; echo ($msg); $form = " <form method=\"post\" action=\"$self\"> <p><label for=\"txtMessage\">Comments:</label> <textarea title=\"Please enter your message\" id=\"txtMessage\" name=\"txtMessage\" rows=\"20\" cols=\"45\">$message</textarea></p> <p><label> </label> <input type=\"submit\" class=\"sendbutton\" name=\"send\" value=\"Submit\" /></p> </form>"; if($send) { $valid=true; if( !$message ) { $errmsg.="Please enter your message:<br />"; $valid=false; } } if( $valid !=true ) { echo( "<span style=\"font-weight: bold; color:red;\">".$errmsg."</span>" . $form ); } else { // Stop the form being used from an external URL // Get the referring URL $referer = $_SERVER['HTTP_REFERER']; // Get the URL of this page $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; // If the referring URL and the URL of this page don't match then // display a message and don't send the email. if ($referer != $this_url) { echo "You do not have permission to use this script from another URL.<br />"; echo "If you are behind a firewall please check your referrer settings."; exit; } // The URLs matched so send the email if( mail($your_email, $subject, $message, "From: $name <$email>")); { // Display the thankyou message echo $thankyou_message; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.