PHP - Add Captcha To Contact Form
hi
i was wondering if anyone had any idea how i can add code A to code b below? code a is my captcha code and code b is my contact form code thanks.. CODE A CAPTCHA: Code: [Select] <?php if(isset($_POST["captcha"])) if($_SESSION["captcha"]==$_POST["captcha"]) { echo 'CAPTHCA is valid; proceed the message'; } else { echo 'CAPTHCA is not valid; ignore submission'; } ?> CODE B CONTACT FORM: Code: [Select] <? $mailto = "me@blah.com"; $cc = ""; $bcc = ""; $subject = "Email subject"; $vname = "blah blah"; $email = $_POST['email']; function validateEmail($email) { if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email)) return true; else return false; } if(strlen($_POST['name']) < 1 || strlen($_POST['message']) < 1 || validateEmail($email) == FALSE) { $emailerror = 'Error:'; if(empty($_POST['name'])) { $emailerror .= '<li>Enter name</li>'; } if(validateEmail($email) == FALSE) { $emailerror .= '<li>Enter valid email</li>'; } if(empty($_POST['message'])) { $emailerror .= '<li>Enter message</li>'; } } else { $emailerror .= "Your email has been sent successfully"; $timestamp = date("F j, Y, g:ia"); $messageproper ="\n\n" . "Name: " . ucwords($_POST['name']) . "\n" . "Email: " . ucwords($email) . "\n" . "Comments: " . $_POST['message'] . "\n" . "\n\n" ; $messageproper = trim(stripslashes($messageproper)); mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() ); } ?> Similar TutorialsHi, I really need to add a captcha to this PHP process form? How do I go about doing this? Code: [Select] <?php // Define some constants define( "RECIPIENT_NAME", "John Smith" ); define( "RECIPIENT_EMAIL", "john@example.com" ); define( "EMAIL_SUBJECT", "Visitor Message" ); // Read the form values $success = false; $senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : ""; $senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : ""; $message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : ""; // If all values exist, send the email if ( $senderName && $senderEmail && $message ) { $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">"; $headers = "From: " . $senderName . " <" . $senderEmail . ">"; $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers ); } // Return an appropriate response to the browser if ( isset($_GET["ajax"]) ) { echo $success ? "success" : "error"; } else { ?> <html> <head> <title>Thanks!</title> </head> <body> <?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?> <?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?> <p>Click your browser's Back button to return to the page.</p> </body> </html> <?php } ?> ?? Thanks in advance! Hello, I am trying to make a captcha, but having some trouble My code matches the tutorial I'm following, the 1st screenshot is the captcha.php file, the 2nd is the captcha_generate.php file, and the 3rd is the result in My browser, I am using firefox and linuxmint 10, with apache2 php5 and GD installed, any Help will be greatly appreciated!!!!! thanx GOD BLESS!!! [attachment deleted by admin] This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319400.0 Just a bit of background first: I have a contact form set up on one of my domains. It hasn't been updated in 7 years and recently I started getting about 3-8 spam messages daily through it. At some point I updated other sites with code that includes a CAPTCHA.
Out of sheer laziness, instead of recoding the contact form that was getting spammed, I just copied & pasted one of the updated forms and changed the necessary details like which e-mail address, URL, etc. Unfortunately, this hasn’t worked out properly.
For some reason the CAPTCHA image isn’t being displayed. I keep looking but can't find the error(s). Could someone please take a look at the code and tell me what went wrong? I’d be ever so grateful for any help! The code for the form itself: <form method="post" action="mail-e.php"> <p><input type="text" name="name" id="name" value="who are you?" size="25" /></p> <p><input type="text" name="email" id="email" value="you@whatever.bla" size="25" /></p> <p><input type="text" name="url" id="url" value="http://" size="25" /></p> <p><textarea name="comments" id="comments" rows="1" cols="20">Go on, then. Tell me a story, wingy!</textarea></p> <p><img src="http://echoing.org/captcha.php" alt="humanity check" /><br /> <input type="text" name="captcha" id="captcha" /> <br /> <p><input type="submit" name="submit" id="submit" value="sing to me" /> <input type="reset" name="reset" id="reset" value="out of key" /></p> </form>mail-e.php: <?php session_start(); //Encrypt the posted code field and then compare with the stored key if(md5($_POST['captcha']) != $_SESSION['key']) { die("Error: You must enter the code correctly"); }else{ echo 'You entered the code correctly'; } ?> <?php if (!isset($_POST['submit'])) { include('./header.php'); echo "<h1>HEY!!! You just encountered an error!</h1>\n <p>You don't belong here. <strong>Because it's <em>wrong</em>.</strong> Go back and try again, please.</p>"; include('./footer.php'); exit; } function cleanUp($data) { $data = strip_tags($data); $data = trim(htmlentities($data)); return $data; } $name = cleanUp($_POST['name']); $email = cleanUp($_POST['email']); $url = cleanUp($_POST['url']); $comments = cleanUp($_POST['comments']); if ((empty($name)) || (empty($email)) || (empty($comments))) { include('./header.php'); echo "<h2>Input Error! Looks like you missed some stuff.</h2>\n <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>"; echo "<form action=\"mail-e.php\" method=\"post\"><p>"; echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />"; echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />"; echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />"; echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />"; echo "<img src=\"http://echoing.org/captcha.php\" alt=\"humanity check\" style=\"margin-bottom: 2px;\" /><br />"; echo "<input type=\"text\" name=\"captcha\" id=\"captcha\" /> <br />"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />"; echo "</p></form>"; include('./footer.php'); exit; } if (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$email)) { include('./header.php'); echo "<h2>Input Error</h2>\n <p>That e-mail address you entered - \"$email\" - is <em>not</em> a valid electronic address. Please edit it and send it in again, please:</p>"; echo "<form action=\"mail-e.php\" method=\"post\"><p>"; echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />"; echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />"; echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />"; echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />"; echo "<img src=\"captcha.php\" alt=\"humanity check\" style=\"margin-bottom: 2px;\" /><br />"; echo "<input type=\"text\" name=\"captcha\" id=\"captcha\" /> <br />"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />"; echo "</p></form>"; include('./footer.php'); exit; } $email = preg_replace("([\r\n])", "", $email); $find = "/(content-type|bcc:|cc:)/i"; if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) { include('./header.php'); echo "<h1>Error</h1>\n <p>No meta/header injections, please.</p>"; include('./footer.php'); exit; } $recipient = "my email address is here"; $subject = "paint me a wish on a velvet sky"; $message = "Name: $name \n"; $message .= "E-mail: $email \n"; $message .= "URL: $url \n"; $message .= "Comments: $comments"; $headers = "From: a wish painted on the velvet sky \r\n"; $headers .= "Reply-To: $email"; if (mail($recipient,$subject,$message,$headers)) { include('./header.php'); echo "<<p>WOO HOO! Your message was successfully sent to me! I'll read it as soon as I can. I may even respond! Thanks for using the form, fruitcake :)</p>"; include('./footer.php'); } else { include('./header.php'); echo "<p>Something went awry. Your message didn't go through. Want to take another crack at it? Please do, I'd love to hear from you!</p>"; include('./footer.php'); } ?>captcha.php: <?php //Start the session so we can store what the code actually is. session_start(); //Now lets use md5 to generate a totally random string $md5 = md5(microtime() * mktime()); /* We dont need a 32 character long string so we trim it down to 5 */ $string = substr($md5,0,5); /* Now for the GD stuff, for ease of use lets create the image from a background image. */ $captcha = imagecreatefromjpeg("http://echoing.org/captcha.jpg"); /* Lets set the colours, the colour $line is used to generate lines. Using a blue misty colours. The colour codes are in RGB */ $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); /* Now to make it a little bit harder for any bots to break, assuming they can break it so far. Lets add some lines in (static lines) to attempt to make the bots life a little harder */ imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); /* Now for the all important writing of the randomly generated string to the image. */ imagestring($captcha, 5, 20, 10, $string, $black); /* Encrypt and store the key inside of a session */ $_SESSION['key'] = md5($string); /* Output the image */ header("Content-type: image/jpeg"); imagejpeg($captcha); ?>I don’t know where it all went wrong as I’m using pretty much the same code without problems here, here and here. The form isn't being used presently (apart from the spam) but I am itching to know what the problem is. P.S. The link to the CAPTCHA image wasn’t always http://echoing.org/captcha.php in the code. On the other forms and initially with this one the code was ./captcha.php but I changed it in case that was the problem. Looks like it isn’t. Thanks in advance! I have a basic question for anyone that can help me. Ive added a captcha input field to the form below, as Im having problems with spam appearing on my testimonial page. 1) How can I prevent the form from being sent if the wrong or no answer is in the form field. 2) How can i have a message appear saying "Sorry wrong answer" if the from isnt sent for the above reason? add.php Code: [Select] <form method="post" action="process2.php" > <textarea rows="25" cols="100" wrap="physical" name="data"> </textarea> <input type="hidden" name="area" value="testimonial"/> What is 5+5? <input type="text" name="captcha"/> <input type="submit" value="Add "> </form> process2.php Code: [Select] <p class="add">Thankyou for submitting your testimonial;</br> <?php $data="<br><br>" . $_POST["data"]; ?><br /> <?php $area=$_POST["area"]; ?> <?php echo $data; ?></p> <?php mysql_query("UPDATE wheelchairwizard SET data = CONCAT(data, '$data') WHERE area = '$area'"); ?> </br> Return to the testimonial page - <a href="http://www.wheelchairwizard.co.uk/testimonials.php">click here</a> HI recently we have been starting to recieved about 30 spam emails aday. I read that the issue was how my forms were submitting and that it kept bypassing the javascript. I found some code i could use at http://chrisplaneta....with_recaptcha/ but i cannot seem to get the form to function correctly.
It is supposed to email me once the form is validated but the email does not seem to be sending.
Also i would like the form to redirect to a thank you page once it has been agreed. I did try but it kept telling me the headers had already been called. i am calling the page in with php include. Can you please advise the best way for me to relocate.
I have attached a copy of my form.php page which has every thing on. I have also included the code at the bottom of this email
Also i would appreciate any comments on what i can include on my form to limit the spammers
<?php //If the form is submitted: if(isset($_POST['submitted'])) { //load recaptcha file require_once('captcha/recaptchalib.php'); //enter your recaptcha private key $privatekey = "6Ld5Df4SAAAAAKciqwDco8dfvBR15fGeFVXWcvCO"; //check recaptcha fields $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); //Check to see if the invisible field has been filled in if(trim($_POST['checking']) !== '') { $blindError = true; } else { //Check to make sure that a contact name has been entered $authorName = (filter_var($_POST['formAuthor'], FILTER_SANITIZE_STRING)); if ($authorName == ""){ $authorError = true; $hasError = true; }else{ $formAuthor = $authorName; }; //Check to make sure sure that a valid email address is submitted $authorEmail = (filter_var($_POST['formEmail'], FILTER_SANITIZE_EMAIL)); if (!(filter_var($authorEmail, FILTER_VALIDATE_EMAIL))){ $emailError = true; $hasError = true; } else{ $formEmail = $authorEmail; }; //Check to make sure the subject of the message has been entered $msgSubject = (filter_var($_POST['formSubject'], FILTER_SANITIZE_STRING)); if ($msgSubject == ""){ $subjectError = true; $hasError = true; }else{ $formSubject = $msgSubject; }; //Check to make sure content has been entered $msgContent = (filter_var($_POST['formContent'], FILTER_SANITIZE_STRING)); if ($msgContent == ""){ $commentError = true; $hasError = true; }else{ $formContent = $msgContent; }; // if all the fields have been entered correctly and there are no recaptcha errors build an email message if (($resp->is_valid) && (!isset($hasError))) { $emailTo = 'carlycyber@hotmail.co.uk'; // here you must enter the email address you want the email sent to $subject = 'A new message from: immigration solicitors Manchester' ; $body = "Name :formAuthor \n\nEmail: $formEmail \n\nTelephone :formSubject \n\nContent: $formContent \n\n$formAuthor"; // This is the body of the email $headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers // Email headers //send email mail($emailTo, $subject, $body, $headers); // set a variable that confirms that an email has been sent $emailSent = true; } // if there are errors in captcha fields set an error variable if (!($resp->is_valid)){ $captchaErrorMsg = true; } } } ?> <?php // if the page the variable "email sent" is set to true show confirmation instead of the form ?> <?php if(isset($emailSent) && $emailSent == true) { ?> <?php $message = "Thank you. Your form has been submitted and a member of our team will contact you shortly.This website is developed for generating immigration enquiries in your area and it is not a law firm, your enquiries will be passed on to a solicitor.We confirm that this website does not belong to a law firm and we have no physical office in your county. Our solicitors are able to provide immigration services all over the UK because they provide a Virtual Service.Responses to your legal enquiries and the legal opinion given to you would be provided by a qualified UK Immigration Solicitor. If you decide to proceed with the solicitor, your matter will be dealt with under a Law firm regulated by the Solicitors Regulatory Authority."; echo "<script type='text/javascript'>alert('$message');</script>"; /*echo "<script language='javascript'> window.location('http://www.immigrationsolicitorsmanchesteruk.co.uk/thankyou.php') </script>";*/ ?> <p>Thank you. Your form has been submitted and a member of our team will contact you shortly.This website is developed for generating immigration enquiries in your area and it is not a law firm, your enquiries will be passed on to a solicitor.We confirm that this website does not belong to a law firm and we have no physical office in your county. </p> <?php } else { ?> <?php // if there are errors in the form show a message ?> <?php if(isset($hasError) || isset($blindError)) { ?> <p><strong>Im sorry. There was an error submitting the form. Please check all the marked fields and try again.</strong></p> <?php } ?> <?php // if there are recaptcha errors show a message ?> <?php if ($captchaErrorMsg){ ?> <p><strong>The recaptcha was not entered correctly. Please try again.</strong></p> <?php } ?> <?php // here, you set what the recaptcha module should look like // possible options: red, white, blackglass and clean // more infor on customisation can be found he http://code.google.com/intl/pl-PL/apis/recaptcha/docs/customization.html ?> <script type="text/javascript"> var RecaptchaOptions = { theme : 'blackglass' }; </script> <?php // this is where the form starts // action attribute should contain url of the page with this form // more on that you can read he http://www.w3schools.com/TAGS/att_form_action.asp ?> <form id="contactForm" action="" method="post"> <p> <strong>Full Name</strong><br/> <input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>"size="25" /></p> <p> <strong>Email </strong><br/> <input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="25" /> </p> <p> <strong>Telephone </strong><br/> <input class="requiredField <?php if($subjectError) { echo 'formError'; } ?>" type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="25" /> </p> <p> <strong>Please give us some information about your enquiry</strong><br/> <textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="25" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea></p> <?php // this field is visible only to robots and screenreaders // if it is filled in it means that a human hasn't submitted this form thus it will be rejected ?> <div id="screenReader"> <label for="checking"> If you want to submit this form, do not enter anything in this field </label> <input type="text" name="checking" id="checking" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" /> </div> </div> <?php // load recaptcha file require_once('captcha/recaptchalib.php'); // enter your public key $publickey = "6Ld5Df4SAAAAANFKozja9bUlDziJ92c31DDt1j6k"; // display recaptcha test fields echo recaptcha_get_html($publickey); ?> <input type="hidden" name="submitted" id="submitted" value="true" /> <?php // submit button ?> <input type="submit" value="Send Message" tabindex="5" id="submit" name="submit"> </form> <?php } // yay! that's all folks! ?>Attached Files form issue.txt 7.58KB 1 downloads Hi, im trying to have a math captcha in my registration form, but having trouble with setting it up in my form. sorry for the large code. If i change the value of $_POST['Submit'] to something else like $_POST['Submit1'] and then same for the math image captcha then it works, but i would like it to work as part of the form, makes sense? lol right now the form just posts the value and doesnt check for captcha values! if someone could help me out here that would be great! thank you. Code: [Select] <?php if(isset($_POST['Submit'])){ if($_POST['Submit'] != $_SESSION['security_number']) { $error = ""; } else { $error = ""; } //NEED TO CHECK IF FIELDS ARE FILLED IN if( empty($_POST['name']) && (empty($_POST['email']))){ header("Location:Messages.php?msg=3"); exit(); } if( empty($_POST['pw1']) && (empty($_POST['pw2']))){ header( "Location:Messages.php?msg=4" ); exit(); } $name=$_POST['name']; $email=$_POST['email']; $pw1=$_POST['pw1']; $pw2=$_POST['pw2']; if("$pw1" !== "$pw2" ){ header( "Location:Messages.php?msg=5" ); exit(); } $ip = $_SERVER['REMOTE_ADDR']; //connect to the db server , check if uname exist include('config.php'); $query1=("Select * from user where email='$email'"); $result1= mysql_query($query1); $num1=mysql_num_rows($result1); if ($num1 > 0) {//Email already been used header( "Location:Messages.php?msg=11" ); exit(); }else{ $query=("Select * from user where uname='$name'"); $result= mysql_query($query); $num=mysql_num_rows($result); if ($num > 0) {//Username already exist header( "Location:Messages.php?msg=6" ); exit(); }else{ //if username does not exist insert user details $query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name',md5('$pw1'),'$email',NOW(),'$ip','Normal')"); if (@mysql_query ($query)) { header("location:login.php?reg=1"); exit; } } } mysql_close(); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <!-- InstanceBeginEditable name="doctitle" --> <title>Registration</title> <!-- InstanceEndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable --> <link href="styleLog.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript"> function reloadCaptcha() { document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date(); } </script> </head> <body> <table width="100%" border="0" cellspacing="7" cellpadding="0"> <tr class="temptitle"> <td><!-- InstanceBeginEditable name="EditRegion4" -->New User Registration <!-- InstanceEndEditable --></td> </tr> <tr> <td><!-- InstanceBeginEditable name="EditRegion3" --> <form name="form1" action="register.php" method="post"> <table width="657" border="0"> <tr> <td width="122"><div align="left">Name</div></td> <td width="525"><input name="name" type="text" size="40"></td> </tr> <tr> <td><div align="left">Email</div></td> <td><input name="email" type="text" size="40"></td> </tr> <tr> <td><div align="left">Password</div></td> <td><input name="pw1" type="password" size="40"></td> </tr> <tr> <td ><div align="left">Confirm Password </div></td> <td><input name="pw2" type="password" size="40"></td> </tr> <tr> <td><img src="math_captcha/image.php" alt="Click to reload image" title="Click to reload image" id="captcha" onclick="javascript:reloadCaptcha()" /></td> <td><input type="text" name="Submit" value="what's the result?" onclick="this.value=''" /></td> <td> </tr> <tr> <td></td> <td> <input name="Submit" type="submit" value="Register"></td> </tr> </table> </form> <?=$error?> MOD EDIT: code tags added. Hi everyone,
I am unable to get the any of the form values to stay after submission with captcha.
My code is below.
Please help. Also the error of the validation doesnt display on submission
<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} .success {color:#360; background-color:#FF0;} .fail {color:#F00; background-color:#FFF;) </style> </head> <body> <?php if (isset($_POST['submit'])){ $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $country = $_POST['country']; $comment = $_POST['comment']; $gender = $_POST['gender']; $to = "laxmon@wikigets.com"; $subject = "New contact form submission"; $message =" A visitor of WIKIGETS has submited a form onine\n\n $name\n\n $email\n\n $phone \n\n $country \n\n $gender\n\n $comment"; require_once('recaptchalib.php'); $privatekey = "6LdK8_YSAAAAAJYPJduOpxhsL4Cy86NgwpCSJCod"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { header ("Location:contact.php?s=2"); } else { mail($to,$subject,$message); header ("Location:contact.php?s=1"); } } ?> <? $country_options= array("select","Afghanistan", "Ã…Land Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia And Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, The Democratic Republic Of The", "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island And Mcdonald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic Of", "Iraq", "Ireland", "Isle Of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People'S Republic Of", "Korea, Republic Of", "Kuwait", "Kyrgyzstan", "Lao People'S Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States Of", "Moldova, Republic Of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Helena", "Saint Kitts And Nevis", "Saint Lucia", "Saint Pierre And Miquelon", "Saint Vincent And The Grenadines", "Samoa", "San Marino", "Sao Tome And Principe", "Saudi Arabia", "Senegal", "Serbia And Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia And The South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard And Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province Of China", "Tajikistan", "Tanzania, United Republic Of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad And Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks And Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis And Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe" ); // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = $countryErr = $phoneErr =""; $name = $email = $gender = $comment = $website = $phone = ""; $country =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address syntax is valid if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["phone"])) { $phone = ""; } else { $phone = test_input($_POST["phone"]); $phone = preg_replace('/\D/', '', $phone); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } $country2 = $_POST['country']; $country3= "select"; if($country2!= $country3) { $country=$country2; } else { $country1 = "Please select your country";} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>CONTACT US</h2> <p><?php $s=$_GET['s']; if($s=='1'){ Echo('<span class= "success"> Success!! An email has been sent to our web team. Please allow 24 hours for a response.</span>'); } else if ($s=='2') { Echo('<span class= "fail">Sorry! Please ensure to fill all feilds correctly</span>' ); } ?> </p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <p>Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr1;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr1;?></span> </p> <p>Phone Number:<input type="text" name="phone" value="<?php echo $phone;?>"> <span class="error"> <?php echo $phoneErr1;?></span> <br> <br> Country: <?php $item = 'select'; echo '<select name="country">'; foreach($country_options as $c) { $sel=''; // Set $sel to empty initially $tag = 'selected="selected"'; if(isset($_POST['country']) && $_POST['country'] == $c) // Here we check if the form has been posted so an error isn't thrown and then check it's value against $c { $sel = $tag; } elseif(!isset($_POST['country']) && $item == $c) // So that the $item doesn't override the posted value we need to check to make sure the form has NOT been submitted also in the { $sel = $tag; } echo '<option value="'.$c.'" '.$sel.'>'.$c.'</option>'; } echo '</select>'; ?> <span class="error">*<?php echo (isset($country1)) ? $country1 : '';?></span> <br><br> <!--Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr1;?></span> <br><br>--> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr1;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br> <?php require_once('recaptchalib.php'); $publickey = "6LdK8_YSAAAAACMvxVRzJ7ZNqjQ9nT_dU6fEZdHx"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <br> <input type="submit" name="submit" value="Submit"> </p> </form> </body> </html> Edited by laxi, 16 July 2014 - 12:45 PM. Hello, I have coded a contact form in PHP and I want to know, if according to you, it is secure! I am new in PHP, so I want some feedback from you. Moreover, I have also two problems based on the contact form. It is a bit complicated to explain, thus, I will break each of my problem one by one. FIRST:The first thing I want to know, is if my contact form secure according to you: The HTML with the PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables to elements $first = htmlentities($_POST['first']); $last = htmlentities($_POST['last']); $sub = htmlentities($_POST['subject']); $email = htmlentities($_POST['email']); $web = htmlentities($_POST['website']); $heard = htmlentities($_POST['heard']); $comment = htmlentities($_POST['message']); $cap = htmlentities($_POST['captcha']); //Declaring the email address with body content $to = 'alithebestofall2010@gmail.com'; $body ="First name: '$first' \n\n Last name: '$last' \n\n Subject: '$sub' \n\n Email: '$email' \n\n Website: '$web' \n\n Heard from us: '$heard' \n\n Comments: '$comment'"; //Validate the forms if (empty($first) || empty($last) || empty($sub) || empty($email) || empty($comment) || empty($cap)) { echo '<p class="error">Required fields must be filled!</p>'; header ('refresh= 3; url= index.php'); return false; } elseif (filter_var($first, FILTER_VALIDATE_INT) || filter_var($last, FILTER_VALIDATE_INT)) { echo '<p class="error">You cannot enter a number as either the first or last name!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Incorrect email address!</p>'; return false; } elseif (!($cap === '12')){ echo '<p class="error">Invalid captcha, try again!</p>'; return false; } else { mail ($to, $sub, $body); echo '<p class="success">Thank you for contacting us!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p>Your first name: <span class="required">*</span></p> <p><input type="text" name="first" size="40" placeholder="Ex: Paul"/></p> <p>Your last name: <span class="required">*</span></p> <p><input type="text" name="last" size="40" placeholder="Ex: Smith"/></p> <p>Subject: <span class="required">*</span></p> <p><input type="text" name="subject" size="40" placeholder="Ex: Contact"/></p> <p>Your email address: <span class="required">*</span></p> <p><input type="text" name="email" size="40" placeholder="Ex: example@xxx.com"/></p> <p>Website:</p> <p><input type="text" name="website" size="40" placeholder="Ex: http//:google.com"/></p> <p>Where you have heard us?: <span class="required">*</span></p> <p><select name="heard"> <option>Internet</option> <option>Newspapers</option> <option>Friends or relatives</option> <option>Others</option> </select></p> <p>Your message: <span class="required">*</span></p> <p><textarea cols="75" rows="20" name="message"></textarea></p> <p>Are you human? Sum this please: 5 + 7 = ?: <span class="required">*</span></p></p> <p><input type="text" name="captcha" size="10"/></p> <p><input type="submit" name="submit" value="Send" class="button"/> <input type="reset" value="Reset" class="button"/></p> </form> SECOND PROBLEM:If a user has made a mistake, he gets the error message so that he can correct! However, when a mistake in the form occurs, all the data the user has entered are disappeared! I want the data to keep appearing so that the user does not start over again to fill the form. THIRD: When the erro message is displayed to notify the user that he made a mistake when submitting the form, the message is displaying on the top of the page. I want it to appear below each respective field. How to do that? In JQuery it is simple, but in PHP, I am confusing! I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> Hello,
I need a contact form with fields:
Name:
Email:
Phone:
Message:
I have html contact form but when a visitor clicks on submit button then a pop up says thnq for contacting us and he need to be on the same page. the details has to get in mail to me.
I have a little problem with my contact form, basically atm I need to paste this code on every page before the HTML tags: Code: [Select] <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['contactname']) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'tekdz@tekdz.com'; //Put your own email address here $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> And this is the code for the contact form: Code: [Select] <div id="contact-wrapper"> <?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p><b>Email Successfully Sent!</b></p> <p>Thank you <strong><?php echo $name;?></strong> for getting in contact with us! Your email was successfully sent and we will be in touch with you soon.</p> <?php } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <div> <label for="name"><strong>Name:</strong></label> <input type="text" size="50" name="contactname" id="contactname" value="" class="required" /> </div> <div> <label for="email"><strong>Email:</strong></label> <input type="text" size="50" name="email" id="email" value="" class="required email" /> </div> <div> <label for="subject"><strong>Phone Number:</strong></label> <input type="text" size="50" name="subject" id="subject" value="" class="required" /> </div> <div> <label for="message"><strong>Message:</strong></label> <textarea rows="5" cols="50" name="message" id="message" class="required"></textarea> </div> <input type="submit" value="Send Message" name="submit" class="submit" /> </form> </div> My question is would it be possible to have the php code that goes before html tags in its own file? So I don't have to manually paste that onto each page with the contact form? Any help will be appreciated, thanks A while ago I purchased a website template which included a contact form, and a PHP script to process the form. I cannot find the contact form so I'm trying to figure out how to code it on my own, or find a similar one to put in it's place. The PHP file is located he http://warp.nazwa.pl/dc/innovation/php/contact/sendMessage.php The form itself is on this page: http://warp.nazwa.pl/dc/innovation/contact.html Here is the code from the JScript file. Code: [Select] // alias to jQuery library, function noConflict release control of the $ variable // to whichever library first implemented it var $j = jQuery.noConflict(); // if true the send button is blocked var g_blockSendButton = false; /*************************************** SETUP CONTACT FORM ****************************************/ function setupInputControls() { // change border color wehen controls take focus $j(".commonInput, .commonTextarea, .contactInputHuman").focus( function() { $j(this).css("border", "1px solid #3399cc"); } ); // restore border color wehen controls lost focus $j(".commonInput, .commonTextarea, .contactInputHuman").blur( function() { $j(this).css("border", "1px solid #ccc"); $j(this).css("border-right", "1px solid #eee"); $j(this).css("border-bottom", "1px solid #eee"); } ); // when input name lost focus, validate the value $j("#inputName").blur( function() { if($j(this).val() != "") { $j("#contactNameErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactNameErrorMsg").html(" Please enter your name").css("visibility", "visible"); } } ); // when input email lost focus validate the value $j("#inputEmail").blur( function() { if($j(this).val() != "") { // create regular expression object var regExp = new RegExp(/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?$/i); // check email address, if result is null the email string dont match to pattern var resultExp = regExp.exec($j(this).val()); if(resultExp == null) { $j(this).css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Sorry, but this email address is incorrect").css("visibility", "visible"); } else { $j("#contactEmailErrorMsg").css("visibility", "hidden"); } } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Please enter your email address").css("visibility", "visible"); } } ); // when input subject lost focus validate the value $j("#inputSubject").blur( function() { if($j(this).val() != "") { $j("#contactSubjectErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactSubjectErrorMsg").html(" You forgot to specify a subject").css("visibility", "visible"); } } ); // when input message lost focus validate the value $j("#inputMessage").blur( function() { if($j(this).val() != "") { $j("#contactMessageErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactMessageErrorMsg").html(" Please enter your message").css("visibility", "visible"); } } ); // when input human lost focus validate the value $j("#inputHuman").blur( function() { if(parseInt($j(this).val(), 10) == 4) { $j("#contactHumanErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactHumanErrorMsg").html(" You really don't know?").css("visibility", "visible"); } } ); } // end of function setupInputControl function setupSendButton() { $j("#contactSendButton").click( function() { // prevent multiple send call by user if(true == g_blockSendButton) { return; } g_blockSendButton = true; // get all data from contact form and save it in local variables var inputName = $j("#inputName").val(); var inputEmail = $j("#inputEmail").val(); var inputSubject = $j("#inputSubject").val(); var inputMessage = $j("#inputMessage").val(); var inputHuman = $j("#inputHuman").val(); // create regular expression object var regExp = new RegExp(/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?$/i); // check email address, if result is null the email string dont match to pattern var resultExp = regExp.exec(inputEmail); // check user answer, resultHuman = true if ok, false if answer is bad var resultHuman = parseInt(inputHuman, 10) == 4; // check the error by logical sum var error = (resultHuman != true) || (resultExp == null) || (inputName == "") || (inputEmail == "") || (inputSubject == "") || (inputMessage == ""); // if there was an error we must display some informotion and mark // input cotrol with wrong data if(error) { $j("#contactNameErrorMsg").css("visibility", "hidden"); $j("#contactEmailErrorMsg").css("visibility", "hidden"); $j("#contactSubjectErrorMsg").css("visibility", "hidden"); $j("#contactMessageErrorMsg").css("visibility", "hidden"); $j("#contactHumanErrorMsg").css("visibility", "hidden"); $j("#contactErrorPanel").slideUp(300); // errors processing if(inputName == "") { $j("#inputName").css("border", "1px solid #FF0000"); $j("#contactNameErrorMsg").html(" Please enter your name").css("visibility", "visible"); } if(inputEmail == "") { $j("#inputEmail").css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Please enter your email adress").css("visibility", "visible"); } else if(resultExp == null) { $j("#inputEmail").css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Sorry, but this email address is incorrect").css("visibility", "visible"); } if(inputSubject == "") { $j("#inputSubject").css("border", "1px solid #FF0000"); $j("#contactSubjectErrorMsg").html(" You forgot to specify a subject").css("visibility", "visible"); } if(inputMessage == "") { $j("#inputMessage").css("border", "1px solid #FF0000"); $j("#contactMessageErrorMsg").html(" Please enter your message").css("visibility", "visible"); } if(resultHuman != true) { $j("#inputHuman").css("border", "1px solid #FF0000"); $j("#contactHumanErrorMsg").html(" You really don't know?").css("visibility", "visible"); } // unblock send button g_blockSendButton = false; } else // if no error, if all data is set correctly { // let's define function called after ajax successfull call function phpCallback(data) { // if success if(data == "ok") { $j("#contactErrorPanel").text(""); $j("#contactErrorPanel").css("background-color", "#ccFFcc"); $j("#contactErrorPanel").append("Your email was sent."); $j("#contactErrorPanel").css("border", "1px solid #339933"); $j("#contactErrorPanel").slideDown(300, function(){ g_blockSendButton = false;}); $j("#inputName").val(""); $j("#inputEmail").val(""); $j("#inputSubject").val(""); $j("#inputMessage").val(""); $j("#inputHuman").val(""); } else // if error/problem during email sending in php script { $j("#contactErrorPanel").text(""); $j("#contactErrorPanel").css("background-color", "#FFcccc"); $j("#contactErrorPanel").css("border", "1px solid #993333"); $j("#contactErrorPanel").append("There was an error sending your email."); $j("#contactErrorPanel").slideDown(300, function(){ g_blockSendButton = false;}); } } // end of function phpCallback // all data is correct so we can hide error/success panel $j("#contactErrorPanel").slideUp(300); // build data string for post call var data = "inputName="+inputName; data += "&"+"inputEmail="+inputEmail; data += "&"+"inputSubject="+inputSubject; data += "&"+"inputMessage="+inputMessage; // try to send email via php script executed by server $j.post("php/contact/sendMessage.php", data, phpCallback, "text"); // unblock send button } // end else all dara } ); } // end of function setupSendButton /*************************************** MAIN CODE - CALL THEN PAGE LOADED ****************************************/ // binding action to event onload page $j(document).ready( function() { // common.js setupGlobal(); setupCommunityButtons(); setupToolTipText(); setupSearchBox(); setupCufonFontReplacement(); setupSideBarMiniSlider(); setupMultiImageLightBox(); setupSidebarTabsPanel(); setupLoadingAsynchronousImages(); setupToolTipImagePreview(); setupTextLabelImagePreview(); // this file setupInputControls(); setupSendButton(); } ); Can anyone help me figure out how to do this by any chance? Hello All, I need some VERY DETAILED direction from anyone who can tell me how to complete this task. I set up my database "riptide" in Php MyAdmin for the following data to be submitted by user. Also a " form.php " form with the following fields. Salutation: Mr. Mrs. Ms. Miss. Dr. Prof. (radio buttons) input name="salutation" type="radio" value="Mr." checked First Name: (text input field) input name="first_Name" Last Name: (text input field) input name="last_Name" E-mail: (text input field) input name="email" Zip Code: (text input field) input name="zip_code" Would you like to receive our email newsletter? Yes No (radio buttons) input type="radio" name="newsletter" value="yes" id="newsletter_0" checked Okay here is my dilemma... I need to make web form that will do the following: (1) Connects to my database (2) INSERTS the form data filled out from my user into my MySQL database. (3) I need an email that will be sent to both me and the user who filled out the web form (4) A Thank you page "displaying" all the details the user filled out in the web form. (5) Plus all fields are required and need " validation " especially the e-mail address. I made a page called "process_form. php" that will handle all of this once the submit button is clicked. How do I make this happen? Thanks in advance James sir i need this contact form php code to make it work,
i make thi deign for my website but dont know what have to put in send.php
here i the code
<h4>Send a Message</h4> <div class="contact-form" method="post" action="send.php"> <form role="form"> <div class="form-group"> <label for="name">Name</label> <input type="text" name="name" placeholder="" id="name" class="form-control"> </div> <div class="form-group"> <label for="email">Email</label> <input type="text" name="email" placeholder="" id="email" class="form-control"> </div> <div class="form-group"> <label for="phone">Skype</label> <input type="text"name="subject" id="phone" class="form-control"> </div> <div class="form-group"> <label for="phone">Message</label> <textarea placeholder="" name="message" rows="5" class="form-control"></textarea> </div> <button class="btn btn-danger" type="submit">Submit</button> </form> Edited by soumikr, 22 December 2014 - 11:35 AM. Hi all, I am currenlty coding up PHP validation for a contact form and as I know barely any PHP i have been following tutorials and copying code. I have a series of checkboxes which emails out the various products that the user wants. It all works now except that it does not re-direct to a thank you page now and outputs this error at the top of the page. Warning: Invalid argument supplied for foreach() in /home2/xxxxxxxx/public_html/client/contact.php on line 17 Below is the code for the PHP and form, any help would be greatly appreciated. Thank you! Code: [Select] <?php if (isset($_POST['submit'])) { $myemail = 'my@email.com';//<-----Put Your email address here. $title = 'Quote'; $name = $_POST['name']; $company = $_POST['company']; $house = $_POST['house']; $street = $_POST['street']; $postcode = $_POST['postcode']; $daynum = $_POST['daynum']; $evenum = $_POST['evenum']; $email = $_POST['email']; $how = $_POST['how']; $information = $_POST['information']; foreach($_POST['product'] as $value) { $product_msg .= " - $value"; } $errors = array(); // set the errors array to empty, by default $fields = array(); // stores the field values $success_message = ""; // import the validation library require("validation.php"); $rules = array(); // stores the validation rules // standard form fields $rules[] = "required,name,Name is required."; $rules[] = "required,house,House number is required."; $rules[] = "required,street,Street is required."; $rules[] = "required,postcode,Post Code is required."; $rules[] = "required,daynum,Daytime Number is required."; $errors = validateFields($_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; } // no errors! redirect the user to the thankyou page (or whatever) else { // here you would either email the form contents to someone or store it in a database. // To redirect to a "thankyou" page, you'd just do this: // header("Location: thanks.php"); $to = $myemail; $email_subject = "Quote: $name"; $email_body = "You have received a new quote from $name. ". " Here are the details:\n \n Name: $name\n \n Company: $company\n \n House: $house\n \n Street: $street\n \n Postcode: $postcode\n \n Daytime Number: $daynum\n \n Evening Number: $evenum\n \n Email: $email\n \n Products: $product_msg\n \n Additional Information: $information\n \n How: $how"; $headers = "From: $title\n"; $headers .= "Reply-To: $email"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: thank-you.html'); } } ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="contact-form" class="cmxform"> <?php // if $errors is not empty, the form must have failed one or more validation // tests. Loop through each and display them on the page for the user if (!empty($errors)) { echo "<div class='phperror'>Please fix the following errors:\n<ul>"; foreach ($errors as $error) echo "<li>$error</li>\n"; echo "</ul></div>"; } if (!empty($message)) { echo "<div class='notify'>$success_message</div>"; } ?> <fieldset> <label for="name">Name:*</label> <label for="name" class="error">Please enter your name.</label> <input class="text" type="text" id="name" name="name" value="<?=$fields['name']?>"/> <label for="company">Company Name:</label> <input class="text" type="text" id="company" name="company"> <label for="house">House Number:*</label> <label for="house" class="error">Please enter your house number.</label> <input class="text" type="text" id="house" name="house" value="<?=$fields['house']?>"> <label for="street">Street Name:*</label> <label for="street" class="error">Please enter your street name.</label> <input class="text" type="text" id="street" name="street" value="<?=$fields['street']?>"> <label for="postcode">Post Code:*</label> <label for="postcode" class="error">Please enter your post code.</label> <input class="text" type="text" id="postcode" name="postcode" value="<?=$fields['postcode']?>"> <label for="daynum">Daytime Number:*</label> <label for="daynum" class="error">Please enter your number.</label> <input class="text" type="text" id="daynum" name="daynum" value="<?=$fields['daynum']?>"> <label for="evenum">Evening Number:</label> <input class="text" type="text" id="eve-num" name="evenum"> <label for="email">Email Address:</label> <input class="text" type="text" id="email" name="email"> </fieldset> <fieldset> <label>Cara Glass Product:</label> <label for="check[]" class="error">Please choose a product.</label> <div id="product"> <div class="radio-btn"> <label for="conservatory">Conservatory</label> <input type="checkbox" value="conservatory" id="conservatory" name="product[]" validate="required:true"/> </div><!--radio-btn--> <div class="radio-btn"> <label for="windows">Windows</label> <input type="checkbox" value="windows" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="fascias">Fascias</label> <input type="checkbox" value="fascias" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="doors">Doors</label> <input type="checkbox" value="doors" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="rooftrim">Rooftrim</label> <input type="checkbox" value="rooftrim" name="product[]" /> </div><!--radio-btn--> </div><!--product--> <label for="information">Additional Information:</label> <textarea id="information" name="information"></textarea> </fieldset> <fieldset> <p>How Did You Hear About Us?</p> <div id="how"> <div class="radio-btn"> <label for="internet">Internet</label> <input type="radio" value="internet" id="internet" name="how"/> </div><!--radio-btn--> <div class="radio-btn"> <label for="letter">Marketing Letter</label> <input type="radio" value="letter" id="letter" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="referral">Referral</label> <input type="radio" value="referral" id="referral" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="advertising">Advertising</label> <input type="radio" value="advertising" id="advertising" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="vans">Our Vans</label> <input type="radio" value="vans" id="vans" name="how" /> </div><!--radio-btn--> </div><!--how--> <p class="submit">Once we have received your details we will call you to arrange a convenient time</p> </fieldset> <input type="submit" name="submit" value="SUBMIT" /> </form> Hello All, I've successfully figure out how to make a form that connects to My Database, INSERTS the END USERS INFO into my database, and THEN sends a email notification back to the ME that contains the the END USERS INFO. Is there a line of CODE in PHP to use that I can ALSO send the END USERS INFO from the form THEY FILLED OUT with all their details that was sent back to ME in the initial e-mail? Also how do I get the date and time to post in the in my e-mail received with from the END USERS containing the date and time of the form filled out. It shows up in my Database HOWEVER, not in my RECEIVED e-mail. Here is my code below: <pre> Code: [Select] <?php if (isset($_POST['submitted'])) { include('connect2myDB.php'); $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; $sqlinsert = "INSERT INTO travelers (salutation, first_name, last_name, email, zip_code, newsletter, registation_date) VALUES ('$salutation', '$first_name','$last_name','$email','$zip_code','$newsletter', NOW()))"; } ?> <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'mrjap1jobs@gmail.com'; // GATHERING the FORM DATA VARIABLES $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; // THIS DATA DOES NOT SHOW UP IN MY RECEIVED E-MAIL HOWEVER, IT DOES SHOW UP IN MY DATABASE.... HOW DO I FIX THIS? $body = <<<EOD <br /><hr><br /> <strong>Salutation:</strong> $salutation <br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Zip Code:</strong> $zip_code <br /> <strong>Newsletter:</strong> $newsletter <br /> <strong>Registration Date:</strong> $registation_date <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> </pre> thanks mrjap1 MOD EDIT: code tags added. Hello All, I made an external "Thank you.html" page that I want to show immediately after the " Send Your Info" button on my "request_more_info.php " form is clicked. This MUST stay external always. I want this to be called in somehow by php. So is there some php code I can use to accomplish this? Also is there some php code I can use to validate my entire form and ESPECIALLY the e-mail address portion on my form? If so could you tell me who do i apply it to my "request_more_info.php " Salutation: (radio buttons) First Name: (input field) Last Name: (input field) Address: (input field) City: (input field) State: (select option) Zip: (input field) Country: (select option) Email: (input field) Our Newsletter: (radio buttons) thanks MrJAP1 hello All, Thank you EVERYONE for all of your help... it was much appreciated. I have created a form that does the following: (1) Connects to the database that created. (2) Inserts the users data into the database (3) Displays a thank you you page after a successful form submission (4) Send an e-mail to me with all the users details I NOW need to be able to send a Custom html page to the end users e-mail with all their data... a Confirmation e-mail for their reference. Is there some special PHP Code that can HANDLE such a task? If so please tell me how might be able to integrate this in my existing code. thanks mrjap1 Hi everyone, i was trying to create a little script for my blog but cant do that. What i want is this model with dropdown options: http://www.pasidedans.ro/inscrie-te-acum I want to replace my entire cod so i dont want to modify him.. Can you help me to create a contact form like this ? thanks ! |