Hi people, im new to php but i have to make a contact form. You can see the page at.... http://www.geneticsweb.co.uk/contact.php im having problems getting it working as you can probably see and i dont know how to fix it or where to start. Any help would be appreciated. Thankyou <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if(isset($_POST['submit'])) { $to = "danielm@design365.co.uk"; $subject = "Genetics Feedback"; $name_field = $_POST['name']; $telephone_field = $_POST['telephone']; $email_field = $_POST['email']; $comments_field = $_POST['comments']; $message = $_GET['message']; $body = "From: $name_field\n E-Mail: $telephone_field\n Telephone: $email_field\n Comments:\n $comments"; if(mail($to, $subject, $body)) { $message = "Sent!";} else { echo "Mail failed"; } function antispam() { // First, make sure the form was posted from a browser. // For basic web-forms, we don't care about anything // other than requests from a browser: if (!isset($_SERVER['HTTP_USER_AGENT'])) { die("Forbidden - You are not authorized to view this page"); exit; } // Make sure the form was indeed POST'ed: // (requires your html form to use: action="post") if (!$_SERVER['REQUEST_METHOD'] == "POST") { die("Forbidden - You are not authorized to view this page"); exit; } // Make sure the form was posted from an approved host name. if (!strstr($_SERVER['HTTP_REFERER'], "cashincar")) { //logBadRequest(); header("HTTP/1.0 403 Forbidden"); exit; } // Attempt to defend against header injections: $badStrings = array("Content-Type:", "MIME-Version:", "Content-Transfer-Encoding:", "bcc:", "cc:", "http://www.genetics.co.uk/contact.php"); // Loop through each POST'ed value and test if it contains // one of the $badStrings: foreach($_POST as $k => $v){ foreach($badStrings as $v2){ if (strpos($v, $v2) !== false) { // logBadRequest(); header("HTTP/1.0 403 Forbidden"); exit; } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>geNetics Web - Next Generation Web Development</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="gen.css"> </head> <body> <div id="wrapper"> <div id="about_us"> <ul> <li><a href="index.html"> Home</a></li> <li><a href="our_team.html">Our team</a></li> <li><a href="about_us.html">About us</a></li> <li><a href="our_work.html">Our work</a></li> <li><a href="contact.php"class="yourhere">Contact</a></li> </ul> <p>Please don't hesitate to contact us, we will be more than happy to help. Simply fill out the form below:</p> <div class="form"><form name="contact" action="contact.php" method="POST"> Your Name:<br> <input class="form_style" name="name" type="text" size="20" maxlength="30"/><br><br> Telephone:<br> <input class="form_style" name="telephone" type="text" size="20" maxlength="20" /><br><br> Email:<br> <input class="form_style" name="email" type="text" size="20" maxlength="50" /><br><br> Comments and Questions:<br> <textarea class="form_style" name="comments" cols="20" rows="5"></textarea><br> <input class="submitbtn" name="submit" type="submit" value="Submit"/> </form> <?php echo $message ; ?> </div> </div> <div id="footer">Next generation web development</div> </body> </html> Code (markup):
Use this ready script I created a while ago, if all fails: http://www.free-php-scripts.net/P/Contact_Form Peace,
Use http://www.dagondesign.com/articles/secure-php-form-mailer-script/ Its one of the best ready-made scripts out there, and takes virtually no setting up. Includes captcha verification if you want it, to reduce spam.