Search the Community
Showing results for tags 'contact form'.
-
Hi I am a newbie with PHP. I created a contact form following a tutorial online and have uploaded the index.html and contact-form.php form to a server with php enabled. I am getting an error message Warning! Please fill all the fields. ”; } else { mail($to,$subject,$msg,”From:”.$email); echo “ I am wondering if anyone can advise me? The PHP: <?php $to="calming1@yahoo.co.uk";/*Your Email*/ $subject="Message from the website"; $date=date("l, F jS, Y"); $time=date("h:i A"); $name=$_REQUEST['name']; $email=$_REQUEST['email']; $message=$_REQUEST['message']; $msg=" Message sent from website form on date $date, hour: $time.\n Name: $name\n Email: $email\n Message: $message\n "; if($email=="") { echo "<div class='alert alert-danger'> <a class='close' data-dismiss='alert'>×</a> <strong>Warning!</strong> Please fill all the fields. </div>"; } else { mail($to,$subject,$msg,"From:".$email); echo "<div class='alert alert-success'> <a class='close' data-dismiss='alert'>×</a> <strong>Thank you for your message!</strong> </div>"; } ?> HTML <form id="contact" class="form-inline" action="contact-form.php" method="post" accept-charset="utf-8"> <div class="form-group pull-left"> <label class="sr-only" for="name">Name</label> <input type="text" class="form-control" id="name" placeholder="Name" name="name"> </div> <div class="form-group pull-right"> <label class="sr-only" for="email">Email</label> <input type="email" class="form-control" id="email" placeholder="Email" name="email"> </div> <textarea class="form-control pull-left" rows="8" placeholder="Message" name="message"></textarea> <button type="submit" class="btn pull-right">Send email</button> </form>
-
I have written a small contact form using .php in Dreamweaver, the message from the webpage does send... except but I cannot see (in my email client) the recipients email address to send the reply to? Moreover; the webpage has three text boxes ‘Name, Email and Message’, in my email client - I can see the person’s name (in subject line), ‘To’... shows up as my email address - i.e. info@website.com and the message is shown as it should be? The code I have written is as followed: <?php $from="reply.info@website.com"; $email="info@website.com"; $to ="info@website.com"; $subject=$_POST['Subject']; $message=$_POST[ 'Message']; mail ( $email, $subject, $message, "From:".$form); Print "Your Message has been sent"; ?>
-
I am using a php contact form and everything is working fine. Just one thing... After the user submits the form a "Message sent!" pops up under the form. Right now the text is quite small. How can I increase that text size? Any help for this beginner would be greatly appreciated! Here is the php code <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('rollnumber','principal','name','email','phone'); $required = array('rollnumber','principal','name','email','phone' ); $your_email = "admin@edev.ie"; $email_subject = "A new message from the CAT4 Indicator Study Reply Form - ".$_POST['rollnumber']; $email_content = "A new message from the CAT4 Indicator Study Reply Form:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?>
-
HELLO EVERYONE I HAVE A HTML FORM ON A HTML PAGE FOR USE AS A FEEDBACK FORM. I WANT TO WRITE THE USER-ENTERED DETAILS INTO A MYSQL DATABASE I AM USING A WEB HOSING SERVICE WHO HAVE TOLD ME THAT TO CONNECT TO THE DATABASE I NEED TO USE PDO (PHP DATABASE OBJECT). HERE IS MY PRESENT PHP CODING TO DO THIS TASK AS OF DATE: <?php if(isset($_POST['email'])) { function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['firstname']) || !isset($_POST['lastname']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['bustype']) || !isset($_POST['description'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $firstname = $_POST['firstname']; // required $lastname = $_POST['lastname']; // required $email = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $bustype = $_POST['bustype']; // required $description = $_POST['description']; // required $con = new PDO("mysql:host=mysql.hostinger.in;dbname=databasename",'username', 'password'); $query = "INSERT INTO `databasename` (`id`, `firstname`, `lastname`, `bustype`, `email`, `telephone`, `description`, `timestamp`,) VALUES (NULL, '$firstname', '$lastname', '$bustype', '$email', '$telephone', '$description', CURRENT_TIMESTAMP,)"; $q = $con->prepare($query); $q->execute(array(':$firstname' => $_POST['firstname'], ':$lastname' => $_POST['lastname'], ':$bustype' => $_POST['bustype'], ':$email' => $_POST['email'],':$telephone' => $_POST['telephone'], ':$description' => $_POST['description'], )); echo "<h2>Thank you for filling in our contact. We shall get back to you as soon as possible.</h2>"; $con = null; ?> but I AM GETTING AN ERROR MESSAGE WHEN I TRY TEST THE HTML FORM PAGE WHICH SAYS PHP Code: Parse error: syntax error, unexpected $end in /home/u196883532/public_html/form.php on line 69 PLUS THERE IS NO DATA WRITTEN TO THE DATABASE. I NEED HELP. WHAT CAN I DO? THANKS
-
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.
-
hey, ive edit a contact form i found on net, changed everything i needed, when i click the "submit" button it shows that the form was send succsesfuly but nothing comes up in the email.. what is wrong ? form code html: <form method="post" action="../booking/booking.php" id="contactform"> <div class="form"> <div class="six columns noleftmargin"> <label>* Company name:</label> <input type="text" name="companyname" class="smoothborder" placeholder="* Company name"/> </div> <div class="six columns noleftmargin"> <label>* Contact name:</label> <input type="text" name="contactname" class="smoothborder" placeholder="* Contact name"/> </div> <p> <div class="six columns noleftmargin"> <label>* Event country:</label> <input type="text" name="country" class="smoothborder" placeholder="* Event country"/> </div> <div class="six columns noleftmargin"> <label>* Event city:</label> <input type="text" name="city" class="smoothborder" placeholder="* Event city"/> </div> <p> <div class="six columns noleftmargin"> <label>* Phone number:</label> <input type="text" name="phone" class="smoothborder" placeholder="* Phone number"/> </div> <div class="six columns noleftmargin"> <label>* Email adress:</label> <input type="text" name="email" class="smoothborder" placeholder="* Email adress"/> <label for="select"></label> </div> <div class="six columns noleftmargin"> <label>* Skype:</label> <input type="text" name="skype" class="smoothborder" placeholder="* Skype"/> <label for="select"></label> </div> <div class="six columns noleftmargin"> <label>* Aritst:</label> <input type="text" name="artist" class="smoothborder" placeholder="* Artist"/> <br> <label for="select"></label> </div> <p> <input type="submit" id="submit" class="readmore" value="Submit"> </p> PHP code: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "info@bouncerecordings.com"; $email_subject = "Booking Request"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['companyname']) || !isset($_POST['contactname']) || !isset($_POST['country']) || !isset($_POST['city']) || !isset($_POST['phone']) || !isset($_POST['email']) || !isset($_POST['skype']) || !isset($_POST['artist'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $companyname = $_POST['companyname']; // required $contactname = $_POST['contactname']; // required $country = $_POST['country']; // required $city = $_POST['city']; // required $phone = $_POST['phone']; // required $email = $_POST['email']; // required $skype = $_POST['skype']; // not required $artist = $_POST['artist']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$companyname)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$contactname)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$country)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$city)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$phone)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$skype)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$artist)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Company Name: ".clean_string($companyname)."\n"; $email_message .= "Contact Name: ".clean_string($contactname)."\n"; $email_message .= "Country: ".clean_string($country)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Phone Number: ".clean_string($phone)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Skype: ".clean_string($skype)."\n"; $email_message .= "Artist: ".clean_string($artist)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?>
-
Hi, Just wondered if anyone can help? A contact form which has previously worked has stopped working, I presume because the PHP has been upgraded to version 5.6. If anyone is able to advise on how I need to tweak it, it would be massively appreciated! Code below: Thanks, Sarah <? // edit these lines $your_name="Company Name"; $your_email="sarah@companyname.co.uk"; $your_web_site_name="companyname.co.uk"; ?> <?php //If the form is submitted if(isset($_POST['name'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) === '') { $commentError = 'Please enter your 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 = $your_email; $subject = 'Contact Form Submission from '.$name; $body = "Name: $name \n\nEmail: $email \n\nPhone: ".trim($_POST['phone'])." \n\nComments: $comments"; $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <?php if(isset($emailSent) == true) { ?> <div class="ok"> <h1>Thanks, <?php echo $name;?></h1> <p>Your email was successfully sent. We will be in touch soon.</p> </div> <?php } ?> <?php if(isset($hasError) ) { ?> <div class="error2">There was an error submitting the form.</div> <?php } ?>
- 8 replies
-
- php
- contact form
-
(and 1 more)
Tagged with:
-
Hi all, firstly thank you in advance to anyone who replies to this thread. I'll be honest I'm a newbie when I comes to PHP and really am a long way to mastering it. If someone could have a look at my code and tell me where I'm going wrong here then it would be a great help. The problem here is, when I click on the submit button it sends me to the PHP script page and doesn't actually send a email to the address. Please Help and again, thank you in advance. Below is the HTML, <section> <div class="container"> <div class="row"> <div class="col-lg-2 col-lg-offset-5"> <hr class="marginbot-50"> </div> </div> <div class="row"> <div class="col-lg-8"> <div class="boxed-grey"> <form data-toggle="validator" role="form" method="post" action="email/contactus.php"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name"> Name</label> <input type="text" class="form-control" name="name" id="name" placeholder="Enter name" required="required" /> </div> <div class="form-group"> <label for="email"> Email Address</label> <div class="clearfix"></div> <div class="input-group"> <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span> </span> <input type="email" class="form-control" name="email" id="email" placeholder="Enter email" required="required" /></div> </div> <div class="form-group"> <label for="contact"> Who would you like to contact?</label> <select id="contact" name="contact" class="form-control" required="required"> <option value="" selected="">Choose One:</option> <option value="Club Chairman">Club Chairman</option> <option value="Sponsorship Secretary">Sponsorship Secretary</option> <option value="Club Captain">Club Captain</option> <option value="Club Website Administrator">Club Website Administrator</option> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name"> Message</label> <textarea name="message" id="message" class="form-control" rows="9" cols="25" required="required" placeholder="Message"></textarea> </div> </div> <div class="col-md-12"> <button type="submit" class="btn btn-skin pull-right" id="btnContactUs"> Send Your Message</button> </div> </div> </form> </div> </div> <div class="col-lg-4"> <div class="widget-contact"> <h5>Write to us</h5> <address> <strong>Abberton & District Cricket Club</strong><br> The Brow<br>Abberton Road<br>Colchester<br>Essex<br>CO5 7AW<br> <abbr title="Phone"><span class="glyphicon glyphicon-phone-alt"></span></abbr> (01206) 735244 </address> <address> <strong>Email</strong><br> <a href="mailto:#">info@abbertoncricket.co.uk</a> </address> <address> <strong>We're on social networks</strong><br> <ul class="company-social"> <li class="social-facebook"><a href="#" target="_blank"><i class="fa fa-facebook"></i></a></li> <li class="social-twitter"><a href="#" target="_blank"><i class="fa fa-twitter"></i></a></li> </ul> </address> </div> </div> </div> </div> </section> The PHP I have is: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $person = $_POST['contact']; $about = $_POST['about']; $query = $_POST['message']; $email_from = $name.'<'.$email.'>'; $to="info@abbertoncricket.co.uk"; $subject="Message from abbertoncricket website"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: ".$email_from."\r\n"; $message=" Hi, My name is $name. <br> I'm looking to contact the <b>$person</b> for your cricket club. <br> The subject title for my message is $about <br> My message is $query <br> If you need to contact me further about this matter then please contact me via my email address below $email <br> Thank you. $name "; if(mail($to,$subject,$message,$headers)) header("Location:../../index.html?msg=Successful Submission! Thankyou for contacting us."); else header("Location:../contact.html?msg=Error To send Email !"); } ?> Again, thankyou for your help. Sam Truss
-
Hello, Im designing a website and have a contact form, what is the best way of managing that and monitor it as just getting that contact form information sent to an email address they may end up having more and more people sending information will get all messy and will surely cause havoc. The only way at the moment i can think of is to store the first piece of information in a database table then store the reply's in a separate table but linked to the original first question by the id. What do you guys things?
-
Hi, I recently bought a HTML template and it came with a contact form which work fines. The only issue I have is that when the email arrives it only shows the persons first name, not their surname unless the name is kept as one e.g.. Adam-Smith I can't see why this is and has been bugging me for the past couple of days! Any ideas? $email_to = "contact@website"; $name = $_POST["user-name"]; $email = $_POST["user-email"]; $message = $_POST["user-message"]; $text = "Name: $name Email: $email Message: $message"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html; charset=utf-8" . "\r\n"; $headers .= "From: <$name>" . "\r\n"; mail($email_to, "Contact", $text, $headers); ?> Thanks
-
Hello all, I am an absolute beginner when it comes to PHP and Javascript but wanted a simple contact form for my website. I used the PHP code from one source and the Javascript validator code from another source and all is working fine except for one very annoying bug: I have to press the Submit button twice in order for the form to send the email. I've found that if the validator is already triggered, however, I only need to press the button once for it to submit. I have scoured the internet for a solution to this problem but am realizing this must be a hangup in the particular code I'm using and I'm just not experienced enough to troubleshoot it. A little help is greatly appreciated. Thank you for your time. Here's the client side code (truncated to only show relevant parts): <html> <head> <script src="js/gen_validatorv4.js" type="text/javascript"></script> </head> <body> <form method="post" action="contact.php" name="contactform"> <div class="row collapse-at-2 half"> <div class="6u"> <input name="name" placeholder="Name" type="text" /> </div> <div class="6u"> <input name="email" placeholder="Email" type="text" /> </div> </div> <div class="row half"> <div class="12u"> <textarea name="message" placeholder="Message"></textarea> </div> </div> <div class="row half"> <div class="12u"> <ul class="actions"> <li><input type="submit" value="Send Message" /></li> <li><input type="reset" value="Clear form" /></li> </ul> </div> </div> </form> <script type="text/javascript"> var myformValidator = new Validator("contactform"); myformValidator.addValidation("name","req", "Please provide your name."); myformValidator.addValidation("email","req", "Please provide your email."); myformValidator.addValidation("message","req", "Please enter your message."); myformValidator.addValidation("email","email", "Please enter a valid email address."); </script> </body> </html> Here's the Javascript validator code: function Validator(frmname) { this.validate_on_killfocus = false; this.formobj = document.forms[frmname]; if (!this.formobj) { alert("Error: couldnot get Form object " + frmname); return; } if (this.formobj.onsubmit) { this.formobj.old_onsubmit = this.formobj.onsubmit; this.formobj.onsubmit = null; } else { this.formobj.old_onsubmit = null; } this.formobj._sfm_form_name = frmname; this.formobj.onsubmit = form_submit_handler; this.addValidation = add_validation; this.formobj.addnlvalidations = new Array(); this.addAddnlValidationFunction = add_addnl_vfunction; this.formobj.runAddnlValidations = run_addnl_validations; this.setAddnlValidationFunction = set_addnl_vfunction;//for backward compatibility this.clearAllValidations = clear_all_validations; this.focus_disable_validations = false; document.error_disp_handler = new sfm_ErrorDisplayHandler(); this.EnableOnPageErrorDisplay = validator_enable_OPED; this.EnableOnPageErrorDisplaySingleBox = validator_enable_OPED_SB; this.show_errors_together = false; this.EnableMsgsTogether = sfm_enable_show_msgs_together; document.set_focus_onerror = true; this.EnableFocusOnError = sfm_validator_enable_focus; this.formobj.error_display_loc = 'right'; this.SetMessageDisplayPos = sfm_validator_message_disp_pos; this.formobj.DisableValidations = sfm_disable_validations; this.formobj.validatorobj = this; } function sfm_validator_enable_focus(enable) { document.set_focus_onerror = enable; } function add_addnl_vfunction() { var proc = { }; proc.func = arguments[0]; proc.arguments = []; for (var i = 1; i < arguments.length; i++) { proc.arguments.push(arguments[i]); } this.formobj.addnlvalidations.push(proc); } function set_addnl_vfunction(functionname) { if(functionname.constructor == String) { alert("Pass the function name like this: validator.setAddnlValidationFunction(DoCustomValidation)\n "+ "rather than passing the function name as string"); return; } this.addAddnlValidationFunction(functionname); } function run_addnl_validations() { var ret = true; for (var f = 0; f < this.addnlvalidations.length; f++) { var proc = this.addnlvalidations[f]; var args = proc.arguments || []; if (!proc.func.apply(null, args)) { ret = false; } } return ret; } function sfm_set_focus(objInput) { if (document.set_focus_onerror) { if (!objInput.disabled && objInput.type != 'hidden') { objInput.focus(); } } } function sfm_disable_validations() { if (this.old_onsubmit) { this.onsubmit = this.old_onsubmit; } else { this.onsubmit = null; } } function sfm_enable_show_msgs_together() { this.show_errors_together = true; this.formobj.show_errors_together = true; } function sfm_validator_message_disp_pos(pos) { this.formobj.error_display_loc = pos; } function clear_all_validations() { for (var itr = 0; itr < this.formobj.elements.length; itr++) { this.formobj.elements[itr].validationset = null; } } function form_submit_handler() { var bRet = true; document.error_disp_handler.clear_msgs(); for (var itr = 0; itr < this.elements.length; itr++) { if (this.elements[itr].validationset && !this.elements[itr].validationset.validate()) { bRet = false; } if (!bRet && !this.show_errors_together) { break; } } if (this.show_errors_together || bRet && !this.show_errors_together) { if (!this.runAddnlValidations()) { bRet = false; } } if (!bRet) { document.error_disp_handler.FinalShowMsg(); return false; } return true; } function add_validation(itemname, descriptor, errstr) { var condition = null; if (arguments.length > 3) { condition = arguments[3]; } if (!this.formobj) { alert("Error: The form object is not set properly"); return; } //if var itemobj = this.formobj[itemname]; if (itemobj.length && isNaN(itemobj.selectedIndex)) //for radio button; don't do for 'select' item { itemobj = itemobj[0]; } if (!itemobj) { alert("Error: Couldnot get the input object named: " + itemname); return; } if (true == this.validate_on_killfocus) { itemobj.onblur = handle_item_on_killfocus; } if (!itemobj.validationset) { itemobj.validationset = new ValidationSet(itemobj, this.show_errors_together); } itemobj.validationset.add(descriptor, errstr, condition); itemobj.validatorobj = this; } function handle_item_on_killfocus() { if (this.validatorobj.focus_disable_validations == true) { /* To avoid repeated looping message boxes */ this.validatorobj.focus_disable_validations = false; return false; } if (null != this.validationset) { document.error_disp_handler.clear_msgs(); if (false == this.validationset.validate()) { document.error_disp_handler.FinalShowMsg(); return false; } } } function validator_enable_OPED() { document.error_disp_handler.EnableOnPageDisplay(false); } function validator_enable_OPED_SB() { document.error_disp_handler.EnableOnPageDisplay(true); } function sfm_ErrorDisplayHandler() { this.msgdisplay = new AlertMsgDisplayer(); this.EnableOnPageDisplay = edh_EnableOnPageDisplay; this.ShowMsg = edh_ShowMsg; this.FinalShowMsg = edh_FinalShowMsg; this.all_msgs = new Array(); this.clear_msgs = edh_clear_msgs; } function edh_clear_msgs() { this.msgdisplay.clearmsg(this.all_msgs); this.all_msgs = new Array(); } function edh_FinalShowMsg() { if (this.all_msgs.length == 0) { return; } this.msgdisplay.showmsg(this.all_msgs); } function edh_EnableOnPageDisplay(single_box) { if (true == single_box) { this.msgdisplay = new SingleBoxErrorDisplay(); } else { this.msgdisplay = new DivMsgDisplayer(); } } function edh_ShowMsg(msg, input_element) { var objmsg = new Array(); objmsg["input_element"] = input_element; objmsg["msg"] = msg; this.all_msgs.push(objmsg); } function AlertMsgDisplayer() { this.showmsg = alert_showmsg; this.clearmsg = alert_clearmsg; } function alert_clearmsg(msgs) { } function alert_showmsg(msgs) { var whole_msg = ""; var first_elmnt = null; for (var m = 0; m < msgs.length; m++) { if (null == first_elmnt) { first_elmnt = msgs[m]["input_element"]; } whole_msg += msgs[m]["msg"] + "\n"; } alert(whole_msg); if (null != first_elmnt) { sfm_set_focus(first_elmnt); } } function sfm_show_error_msg(msg, input_elmt) { document.error_disp_handler.ShowMsg(msg, input_elmt); } function SingleBoxErrorDisplay() { this.showmsg = sb_div_showmsg; this.clearmsg = sb_div_clearmsg; } function sb_div_clearmsg(msgs) { var divname = form_error_div_name(msgs); sfm_show_div_msg(divname, ""); } function sb_div_showmsg(msgs) { var whole_msg = "<ul>\n"; for (var m = 0; m < msgs.length; m++) { whole_msg += "<li>" + msgs[m]["msg"] + "</li>\n"; } whole_msg += "</ul>"; var divname = form_error_div_name(msgs); var anc_name = divname + "_loc"; whole_msg = "<a name='" + anc_name + "' >" + whole_msg; sfm_show_div_msg(divname, whole_msg); window.location.hash = anc_name; } function form_error_div_name(msgs) { var input_element = null; for (var m in msgs) { input_element = msgs[m]["input_element"]; if (input_element) { break; } } var divname = ""; if (input_element) { divname = input_element.form._sfm_form_name + "_errorloc"; } return divname; } function sfm_show_div_msg(divname,msgstring) { if(divname.length<=0) return false; if(document.layers) { divlayer = document.layers[divname]; if(!divlayer){return;} divlayer.document.open(); divlayer.document.write(msgstring); divlayer.document.close(); } else if(document.all) { divlayer = document.all[divname]; if(!divlayer){return;} divlayer.innerHTML=msgstring; } else if(document.getElementById) { divlayer = document.getElementById(divname); if(!divlayer){return;} divlayer.innerHTML =msgstring; } divlayer.style.visibility="visible"; return false; } function DivMsgDisplayer() { this.showmsg = div_showmsg; this.clearmsg = div_clearmsg; } function div_clearmsg(msgs) { for (var m in msgs) { var divname = element_div_name(msgs[m]["input_element"]); show_div_msg(divname, ""); } } function element_div_name(input_element) { var divname = input_element.form._sfm_form_name + "_" + input_element.name + "_errorloc"; divname = divname.replace(/[\[\]]/gi, ""); return divname; } function div_showmsg(msgs) { var whole_msg; var first_elmnt = null; for (var m in msgs) { if (null == first_elmnt) { first_elmnt = msgs[m]["input_element"]; } var divname = element_div_name(msgs[m]["input_element"]); show_div_msg(divname, msgs[m]["msg"]); } if (null != first_elmnt) { sfm_set_focus(first_elmnt); } } function show_div_msg(divname, msgstring) { if (divname.length <= 0) return false; if (document.layers) { divlayer = document.layers[divname]; if (!divlayer) { return; } divlayer.document.open(); divlayer.document.write(msgstring); divlayer.document.close(); } else if (document.all) { divlayer = document.all[divname]; if (!divlayer) { return; } divlayer.innerHTML = msgstring; } else if (document.getElementById) { divlayer = document.getElementById(divname); if (!divlayer) { return; } divlayer.innerHTML = msgstring; } divlayer.style.visibility = "visible"; } function ValidationDesc(inputitem, desc, error, condition) { this.desc = desc; this.error = error; this.itemobj = inputitem; this.condition = condition; this.validate = vdesc_validate; } function vdesc_validate() { if (this.condition != null) { if (!eval(this.condition)) { return true; } } if (!validateInput(this.desc, this.itemobj, this.error)) { this.itemobj.validatorobj.focus_disable_validations = true; sfm_set_focus(this.itemobj); return false; } return true; } function ValidationSet(inputitem, msgs_together) { this.vSet = new Array(); this.add = add_validationdesc; this.validate = vset_validate; this.itemobj = inputitem; this.msgs_together = msgs_together; } function add_validationdesc(desc, error, condition) { this.vSet[this.vSet.length] = new ValidationDesc(this.itemobj, desc, error, condition); } function vset_validate() { var bRet = true; for (var itr = 0; itr < this.vSet.length; itr++) { bRet = bRet && this.vSet[itr].validate(); if (!bRet && !this.msgs_together) { break; } } return bRet; } /* checks the validity of an email address entered * returns true or false */ function validateEmail(email) { var splitted = email.match("^(.+)@(.+)$"); if (splitted == null) return false; if (splitted[1] != null) { var regexp_user = /^\"?[\w-_\.]*\"?$/; if (splitted[1].match(regexp_user) == null) return false; } if (splitted[2] != null) { var regexp_domain = /^[\w-\.]*\.[A-Za-z]{2,4}$/; if (splitted[2].match(regexp_domain) == null) { var regexp_ip = /^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/; if (splitted[2].match(regexp_ip) == null) return false; } // if return true; } return false; } function TestComparison(objValue, strCompareElement, strvalidator, strError) { var bRet = true; var objCompare = null; if (!objValue.form) { sfm_show_error_msg("Error: No Form object!", objValue); return false } objCompare = objValue.form.elements[strCompareElement]; if (!objCompare) { sfm_show_error_msg("Error: Element with name" + strCompareElement + " not found !", objValue); return false; } var objval_value = objValue.value; var objcomp_value = objCompare.value; if (strvalidator != "eqelmnt" && strvalidator != "neelmnt") { objval_value = objval_value.replace(/\,/g, ""); objcomp_value = objcomp_value.replace(/\,/g, ""); if (isNaN(objval_value)) { sfm_show_error_msg(objValue.name + ": Should be a number ", objValue); return false; } //if if (isNaN(objcomp_value)) { sfm_show_error_msg(objCompare.name + ": Should be a number ", objCompare); return false; } //if } //if var cmpstr = ""; switch (strvalidator) { case "eqelmnt": { if (objval_value != objcomp_value) { cmpstr = " should be equal to "; bRet = false; } //if break; } //case case "ltelmnt": { if (eval(objval_value) >= eval(objcomp_value)) { cmpstr = " should be less than "; bRet = false; } break; } //case case "leelmnt": { if (eval(objval_value) > eval(objcomp_value)) { cmpstr = " should be less than or equal to"; bRet = false; } break; } //case case "gtelmnt": { if (eval(objval_value) <= eval(objcomp_value)) { cmpstr = " should be greater than"; bRet = false; } break; } //case case "geelmnt": { if (eval(objval_value) < eval(objcomp_value)) { cmpstr = " should be greater than or equal to"; bRet = false; } break; } //case case "neelmnt": { if (objval_value.length > 0 && objcomp_value.length > 0 && objval_value == objcomp_value) { cmpstr = " should be different from "; bRet = false; } //if break; } } //switch if (bRet == false) { if (!strError || strError.length == 0) { strError = objValue.name + cmpstr + objCompare.name; } //if sfm_show_error_msg(strError, objValue); } //if return bRet; } function TestSelMin(objValue, strMinSel, strError) { var bret = true; var objcheck = objValue.form.elements[objValue.name]; var chkcount = 0; if (objcheck.length) { for (var c = 0; c < objcheck.length; c++) { if (objcheck[c].checked == "1") { chkcount++; } //if } //for } else { chkcount = (objcheck.checked == "1") ? 1 : 0; } var minsel = eval(strMinSel); if (chkcount < minsel) { if (!strError || strError.length == 0) { strError = "Please Select atleast" + minsel + " check boxes for" + objValue.name; } //if sfm_show_error_msg(strError, objValue); bret = false; } return bret; } function TestSelMax(objValue, strMaxSel, strError) { var bret = true; var objcheck = objValue.form.elements[objValue.name]; var chkcount = 0; if (objcheck.length) { for (var c = 0; c < objcheck.length; c++) { if (objcheck[c].checked == "1") { chkcount++; } //if } //for } else { chkcount = (objcheck.checked == "1") ? 1 : 0; } var maxsel = eval(strMaxSel); if (chkcount > maxsel) { if (!strError || strError.length == 0) { strError = "Please Select atmost " + maxsel + " check boxes for" + objValue.name; } //if sfm_show_error_msg(strError, objValue); bret = false; } return bret; } function IsCheckSelected(objValue, chkValue) { var selected = false; var objcheck = objValue.form.elements[objValue.name]; if (objcheck.length) { var idxchk = -1; for (var c = 0; c < objcheck.length; c++) { if (objcheck[c].value == chkValue) { idxchk = c; break; } //if } //for if (idxchk >= 0) { if (objcheck[idxchk].checked == "1") { selected = true; } } //if } else { if (objValue.checked == "1") { selected = true; } //if } //else return selected; } function TestDontSelectChk(objValue, chkValue, strError) { var pass = true; pass = IsCheckSelected(objValue, chkValue) ? false : true; if (pass == false) { if (!strError || strError.length == 0) { strError = "Can't Proceed as you selected " + objValue.name; } //if sfm_show_error_msg(strError, objValue); } return pass; } function TestShouldSelectChk(objValue, chkValue, strError) { var pass = true; pass = IsCheckSelected(objValue, chkValue) ? true : false; if (pass == false) { if (!strError || strError.length == 0) { strError = "You should select" + objValue.name; } //if sfm_show_error_msg(strError, objValue); } return pass; } function TestRequiredInput(objValue, strError) { var ret = true; if (VWZ_IsEmpty(objValue.value)) { ret = false; } //if else if (objValue.getcal && !objValue.getcal()) { ret = false; } if (!ret) { if (!strError || strError.length == 0) { strError = objValue.name + " : Required Field"; } //if sfm_show_error_msg(strError, objValue); } return ret; } function TestFileExtension(objValue, cmdvalue, strError) { var ret = false; var found = false; if (objValue.value.length <= 0) { //The 'required' validation is not done here return true; } var extns = cmdvalue.split(";"); for (var i = 0; i < extns.length; i++) { ext = objValue.value.substr(objValue.value.length - extns[i].length, extns[i].length); ext = ext.toLowerCase(); if (ext == extns[i]) { found = true; break; } } if (!found) { if (!strError || strError.length == 0) { strError = objValue.name + " allowed file extensions are: " + cmdvalue; } //if sfm_show_error_msg(strError, objValue); ret = false; } else { ret = true; } return ret; } function TestMaxLen(objValue, strMaxLen, strError) { var ret = true; if (eval(objValue.value.length) > eval(strMaxLen)) { if (!strError || strError.length == 0) { strError = objValue.name + " : " + strMaxLen + " characters maximum "; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestMinLen(objValue, strMinLen, strError) { var ret = true; if (eval(objValue.value.length) < eval(strMinLen)) { if (!strError || strError.length == 0) { strError = objValue.name + " : " + strMinLen + " characters minimum "; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestInputType(objValue, strRegExp, strError, strDefaultError) { var ret = true; var charpos = objValue.value.search(strRegExp); if (objValue.value.length > 0 && charpos >= 0) { if (!strError || strError.length == 0) { strError = strDefaultError; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestEmail(objValue, strError) { var ret = true; if (objValue.value.length > 0 && !validateEmail(objValue.value)) { if (!strError || strError.length == 0) { strError = objValue.name + ": Enter a valid Email address "; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestLessThan(objValue, strLessThan, strError) { var ret = true; var obj_value = objValue.value.replace(/\,/g, ""); strLessThan = strLessThan.replace(/\,/g, ""); if (isNaN(obj_value)) { sfm_show_error_msg(objValue.name + ": Should be a number ", objValue); ret = false; } //if else if (eval(obj_value) >= eval(strLessThan)) { if (!strError || strError.length == 0) { strError = objValue.name + " : value should be less than " + strLessThan; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestGreaterThan(objValue, strGreaterThan, strError) { var ret = true; var obj_value = objValue.value.replace(/\,/g, ""); strGreaterThan = strGreaterThan.replace(/\,/g, ""); if (isNaN(obj_value)) { sfm_show_error_msg(objValue.name + ": Should be a number ", objValue); ret = false; } //if else if (eval(obj_value) <= eval(strGreaterThan)) { if (!strError || strError.length == 0) { strError = objValue.name + " : value should be greater than " + strGreaterThan; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestRegExp(objValue, strRegExp, strError) { var ret = true; if (objValue.value.length > 0 && !objValue.value.match(strRegExp)) { if (!strError || strError.length == 0) { strError = objValue.name + ": Invalid characters found "; } //if sfm_show_error_msg(strError, objValue); ret = false; } //if return ret; } function TestDontSelect(objValue, dont_sel_value, strError) { var ret = true; if (objValue.value == null) { sfm_show_error_msg("Error: dontselect command for non-select Item", objValue); ret = false; } else if (objValue.value == dont_sel_value) { if (!strError || strError.length == 0) { strError = objValue.name + ": Please Select one option "; } //if sfm_show_error_msg(strError, objValue); ret = false; } return ret; } function TestSelectOneRadio(objValue, strError) { var objradio = objValue.form.elements[objValue.name]; var one_selected = false; for (var r = 0; r < objradio.length; r++) { if (objradio[r].checked == "1") { one_selected = true; break; } } if (false == one_selected) { if (!strError || strError.length == 0) { strError = "Please select one option from " + objValue.name; } sfm_show_error_msg(strError, objValue); } return one_selected; } function TestSelectRadio(objValue, cmdvalue, strError, testselect) { var objradio = objValue.form.elements[objValue.name]; var selected = false; for (var r = 0; r < objradio.length; r++) { if (objradio[r].value == cmdvalue && objradio[r].checked == "1") { selected = true; break; } } if (testselect == true && false == selected || testselect == false && true == selected) { sfm_show_error_msg(strError, objValue); return false; } return true; } //* Checks each field in a form function validateInput(strValidateStr, objValue, strError) { var ret = true; var epos = strValidateStr.search("="); var command = ""; var cmdvalue = ""; if (epos >= 0) { command = strValidateStr.substring(0, epos); cmdvalue = strValidateStr.substr(epos + 1); } else { command = strValidateStr; } switch (command) { case "req": case "required": { ret = TestRequiredInput(objValue, strError) break; } case "maxlength": case "maxlen": { ret = TestMaxLen(objValue, cmdvalue, strError) break; } case "minlength": case "minlen": { ret = TestMinLen(objValue, cmdvalue, strError) break; } case "alnum": case "alphanumeric": { ret = TestInputType(objValue, "[^A-Za-z0-9]", strError, objValue.name + ": Only alpha-numeric characters allowed "); break; } case "alnum_s": case "alphanumeric_space": { ret = TestInputType(objValue, "[^A-Za-z0-9\\s]", strError, objValue.name + ": Only alpha-numeric characters and space allowed "); break; } case "num": case "numeric": case "dec": case "decimal": { if (objValue.value.length > 0 && !objValue.value.match(/^[\-\+]?[\d\,]*\.?[\d]*$/)) { sfm_show_error_msg(strError, objValue); ret = false; } //if break; } case "alphabetic": case "alpha": { ret = TestInputType(objValue, "[^A-Za-z]", strError, objValue.name + ": Only alphabetic characters allowed "); break; } case "alphabetic_space": case "alpha_s": { ret = TestInputType(objValue, "[^A-Za-z\\s]", strError, objValue.name + ": Only alphabetic characters and space allowed "); break; } case "email": { ret = TestEmail(objValue, strError); break; } case "lt": case "lessthan": { ret = TestLessThan(objValue, cmdvalue, strError); break; } case "gt": case "greaterthan": { ret = TestGreaterThan(objValue, cmdvalue, strError); break; } case "regexp": { ret = TestRegExp(objValue, cmdvalue, strError); break; } case "dontselect": { ret = TestDontSelect(objValue, cmdvalue, strError) break; } case "dontselectchk": { ret = TestDontSelectChk(objValue, cmdvalue, strError) break; } case "shouldselchk": { ret = TestShouldSelectChk(objValue, cmdvalue, strError) break; } case "selmin": { ret = TestSelMin(objValue, cmdvalue, strError); break; } case "selmax": { ret = TestSelMax(objValue, cmdvalue, strError); break; } case "selone_radio": case "selone": { ret = TestSelectOneRadio(objValue, strError); break; } case "dontselectradio": { ret = TestSelectRadio(objValue, cmdvalue, strError, false); break; } case "selectradio": { ret = TestSelectRadio(objValue, cmdvalue, strError, true); break; } //Comparisons case "eqelmnt": case "ltelmnt": case "leelmnt": case "gtelmnt": case "geelmnt": case "neelmnt": { return TestComparison(objValue, cmdvalue, command, strError); break; } case "req_file": { ret = TestRequiredInput(objValue, strError); break; } case "file_extn": { ret = TestFileExtension(objValue, cmdvalue, strError); break; } } //switch return ret; } function VWZ_IsListItemSelected(listname, value) { for (var i = 0; i < listname.options.length; i++) { if (listname.options[i].selected == true && listname.options[i].value == value) { return true; } } return false; } function VWZ_IsChecked(objcheck, value) { if (objcheck.length) { for (var c = 0; c < objcheck.length; c++) { if (objcheck[c].checked == "1" && objcheck[c].value == value) { return true; } } } else { if (objcheck.checked == "1") { return true; } } return false; } function sfm_str_trim(strIn) { return strIn.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } function VWZ_IsEmpty(value) { value = sfm_str_trim(value); return (value.length) == 0 ? true : false; } And here's the contact.php code referenced client side: <?php $errors = ''; $name = $_POST['name']; $email_address = $_POST['email']; $message = $_POST['message']; $myemail = 'email address removed for privacy';//<-----Put Your email address here. if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) { $errors .= "\n Error: all fields are required"; return false; } if (!preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address."; return false; } if( empty($errors)) { $to = $myemail; $email_subject = "Contact form submission: $name"; $email_body = "You have received a new message ". " Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: contact-form-thank-you.html'); } ?> <!DOCTYPE HTML> <html> <head> <title>Contact Form Error</title> <script> function goBack() { window.history.back() } </script> <link rel="stylesheet" href="css/skel.css" /> <link rel="stylesheet" href="css/style.css" /> <!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]--> </head> <body> <!-- This page is displayed only if there is some error --> <p style="text-align: center;"><?php echo nl2br($errors); ?></p> <p style="text-align: center;"><button onclick="goBack()">Go Back</button></p> </body> </html>
-
Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: <!DOCTYPE html> <html lang="en"> <?php if (!count($_POST)){ ?> <form method="post" id="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>"> </form> <?php }else{ ?> <?php $mail = $_POST['email']; /*$subject = "".$_POST['subject'];*/ $to = "...admin@yahoo.com"; $subject = "Message from Digital ......"; $headers = "From: YourName <noreply@..........com>"; $message = "Message from YourName\n"; $message .= "\nName: " . $_POST['Name']; $message .= "\nEmail: " . $_POST['Email']; $message .= "\nMessage: " . $_POST['Message']; //Receive Variable $sentOk = mail($to,$subject,$message,$headers); } ?> <!-- END SEND MAIL SCRIPT --> </html> This is all that sends: Message from YourName Name: Email: Message:
-
I am really sorry for my silly question. I need a contact form with just two fields: "Name" and "Phone", and "Submit" button. Don't know why, but couple PHP scripts I used before don't work this time. Many scripts from the net I found this week don't work correctly as well even if I change nothing. Finally I found one that works, however, there are 5 fields in the form. I eliminated 3 of them (and it still works), but I can't solve the problem how to change "email" to "phone". All efforts to do it were unsuccessful. Could you help me with that? Thanx a lot. Alex. <form name="contactform" method="post" action="contacts.php"> <label for="first_name">First Name *</label> <input type="text" name="first_name" maxlength="50" size="30"> <label for="email">Email Address *</label> <input type="text" name="email" maxlength="80" size="30"> <input type="submit" value="Submit"> </form> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "supetraveller@gmail.com"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['email'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $email_from = $_POST['email']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?>
-
I am currently trying to build a contact form for a website. I have been given a script to use that was used on another site but it has an iff statement in it to change the strEmail according to the location and requirement. I would like to remove this as the form no longer has location or requirement and just have it post to a single email address. Below is the process php for the form. I only have name, surname, phone, email and comment on this new form so nothing else is needed. I also have to remove the insert into database. any help would be appreciated! thank you <?php //THIS NEEDS TO BE AT THE TOP OF THE PAGE, BEFORE ANY HTML IS OUTPUT TO CLIENT $strMessage = ""; if ($_SERVER['REMOTE_ADDR'] == "5.71.114.48") { error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); } //Only action if the form has been submitted if(isset($_POST['submit-generic'])) { //Validate the fields again, because not everyone has Javascript, including bots if (isset($_POST['location']) && $_POST['location'] !== "" && isset($_POST['requirement']) && $_POST['requirement'] !== "" && isset($_POST['name']) && $_POST['name'] !== "" && isset($_POST['surname']) && $_POST['surname'] !== "" && isset($_POST['email']) && $_POST['email'] !== "" && $_POST['surname'] !== $_POST['name']) { switch ($_POST['location']) { case 'United States': $strEmail = "EMAIL-HERE"; break; } //Open DB $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (mysqli_connect_error()) $db = false; //Prepare statement if ($db) { $insertStmt = $db->prepare("INSERT INTO enquiries (EnquiryType, EnquiryEmail, EnquiryFirstName, EnquiryLastName, EnquiryPhone, EnquiryCompany, EnquiryPosition, EnquiryRequirement, EnquiryMessage, EnquiryLocationOfInterest, EnquiryDateTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW());"); $insertStmt->bind_param('ssssssssss', $type, $email, $firstName, $lastName, $phone, $company, $position, $requirement, $enquiry, $officeOfInterest); } //Sanitize data $type = "contact-form"; $firstName = $_POST['name']; $lastName = $_POST['surname']; $email = $_POST['email']; $phone = $_POST['phone']; $company = $_POST['company']; $position = $_POST['position']; if ($_POST['requirement'] == "Other") { $requirement = $_POST['other-requirement']; } else { $requirement = $_POST['requirement']; } $enquiry = $_POST['comment']; if ($_POST['location'] == "Other") { $officeOfInterest = $_POST['other-location']; } else { $officeOfInterest = $_POST['location']; } //Insert Data to DB if ($db) { $insertStmt->execute(); $insertStmt->close(); $db->close(); } //Send to client $strFrom = "EMAIL HERE"; $strTo = $strEmail; $strSubject = "New contact on from " . $_POST['name'] . " " . $_POST['surname']; $strBody = ' <html> <body> <h1>New contact form</h1> <p>Information on form was:</p> <p><strong>Name</strong>: '.$_POST['name'].'</p> <p><strong>Surname</strong>: '.$_POST['surname'].'</p> <p><strong>Email</strong>: '.$_POST['email'].'</p> <p><strong>Phone</strong>: '.$_POST['phone'].'</p> <p><strong>Company</strong>: '.$_POST['company'].'</p> <p><strong>Position</strong>: '.$_POST['position'].'</p> <p><strong>Location</strong>: '.$_POST['location'].'</p> <p><strong>Other Location</strong>: '.$_POST['location-other'].'</p> <p><strong>Requirement</strong>: '.$_POST['requirement'].'</p> <p><strong>Other</strong>: '.$_POST['other-requirement'].'</p> <p><strong>Enquiry</strong>: '.$_POST['comment'].'</p> </body> </html> '; $strHeaders = 'From: '.$strFrom."\r\n". 'Reply-To: '.$strFrom."\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n". 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n"; mail($strEmail, $strSubject, $strBody, $strHeaders); //Send confirmation to customer $strFrom = "EMAIL HERE"; $strTo = $_POST['email']; $strSubject = "Thank you for contacting"; $strBody = "Thanks for getting in touch. Your message has been received and will be processed as soon as possible."; $strHeaders = 'From: '.$strFrom."\r\n". 'Reply-To: '.$strFrom."\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($strTo, $strSubject, $strBody, $strHeaders); //Finally redirect header('Location: /contact-us/thank-you?contactlocation='.$_POST['location'].'?requirement='.$requirement) ; exit(); } else { //Finally redirect header('Location: '.$_SERVER['REQUEST_URI']. '?message=Please complete the required fields.') ; exit(); } } ?>
- 2 replies
-
- contact form
- form
-
(and 1 more)
Tagged with:
-
This contact form works fairly well, but I do get spam. Can you add something to this existing form that will make it a little better at not letting spam thru? <form action="../page.php?page=1" method="post" name="contact_us" onSubmit="return capCheck(this);"> <table cellpadding="5" width="100%"> <tr> <td width="10" class="required_field">*</td> <td width="80">Name</td> <td><input type="text" name="name" maxlength="50" style="width:400px; border: 1px solid #696969;" /><br /><br /></td> </tr> <tr> <td class="required_field">*</td> <td>Email Address</td> <td><input type="text" name="email" maxlength="40" style="width:400px; border: 1px solid #696969;" /><br /><br /></td> </tr> <tr> <td></td> <td>Subject:</td> <td><input type="text" name="subject" maxlength="40" style="width:400px; border: 1px solid #696969;"/><br /><br /></td> </tr> <tr> <td class="required_field">*</td> <td>Enter Image Code:</td> <td><input type="text" value="" name="captext" style="width: 100px" maxlength="6" /></td> </tr> <tr> <td></td> <td><a onclick="refresh_security_image(); return false;" style="cursor:pointer;"><u>Refresh Image</u></a></td> <td><img src="../includes/captcha.php" border="0" id="verificiation_image" /></a></td> </tr> </table> <br/> <p> <input type="hidden" name="submited" value="1" /> <input type="submit" name="submit" value="Submit" style="margin:7px 10px 0px 0px; padding:10px 0px 10px 0px; font-size:15px; font-style:Century-Gothic;" /> </p> </form> </td> </tr> </table> </div> <script type="text/javascript"> <!-- function refresh_security_image() { var new_url = new String("../includes/captcha.php?width=132&height=36&charcators="); new_url = new_url.substr(0, new_url.indexOf("width=") + 37); // we need a random new url so this refreshes var chr_str = "123456789"; for(var i=0; i < 6; i++) new_url = new_url + chr_str.substr(Math.floor(Math.random() * 2), 1); document.getElementById("verificiation_image").src = new_url; } --> </script> <!-- captch start --> <script type="text/javascript" id="clientEventHandlersJS" language="javascript"> </script> <!-- captch end --> Thanks
-
Hello I've got this form that keeps messing up. You can get to the link here: http://alexis-apparel.host56.com/ Attached below are all the files. I must have this done by the end of the month please help index.html html_form_send.php upload_file.php
- 2 replies
-
- contact form
- php
-
(and 1 more)
Tagged with:
-
Hello you awesome coders. I am getting a strange mesage on this site and need some help if you can to fix. the site is showing this error Notice: Undefined index: Submit in E:\Domains\a\aet.uk.net\user\htdocs\contact.php on line 84 at this page; http://aet.uk.net/contact.php Can you help! the form wont post or work. cheers chris <?php include_once("photoman/common.php");?> <!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> <?php include("includes/header.php"); ?> <script language="JavaScript" type="text/javascript" src="<?php echo $pref ?>scripts/formcheck.js"></script> </head> <body> <?php include("includes/banner.php"); ?> <div id="content" class="<?php echo $sectname ?>"> <?php $pageimage = "includes/$sectname.swf"; if (file_exists($pageimage)) { ?> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','789','height','197','title','<?php echo $sectname." page" ?>','src','includes/<?php echo $sectname ?>','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','includes/<?php echo $sectname ?>' ); //end AC code </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="789" height="197" title="<?php echo $sectname." page" ?>"> <param name="movie" value="includes/<?php echo $sectname ?>.swf" /> <param name="quality" value="high" /> <embed src="includes/<?php echo $sectname ?>.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed> </object></noscript> <?php } else { $pageimage = "includes/$sectname.jpg"; $pagemax = 250; if (file_exists($pageimage)) { list($sw, $sh, $type, $attr) = getimagesize($pageimage); printf("<div id='pagephoto'><img src=%s alt='%s' %s></div>", $pageimage, $sectname." page image", $attr ); } else { $pageimage = "includes/$sectname.gif"; if (file_exists($pageimage)) { list($sw, $sh, $typwe, $attr) = getimagesize($pageimage); printf("<div id='pagephoto'><img src=%s %s></div>", $pageimage, $attr); } } } ?> <?php $submenu = getMenuXML($sectname); if (count($submenu) > 0 ) { ?> <ul> <?php foreach ($submenu as $subitem) { $imagename = $subitem['image']; if ($imagename == "") { ?> <li><a href="<?php echo $pref ?><?php echo $subitem['href']; ?>"> <?php echo $subitem['name']; ?> </a> </li> <?php } else { ?> <li><a href="<?php echo $pref ?><?php echo $subitem['href']; ?>" onmouseover="MM_swapImage('<?php echo $imagename; ?>','','<?php echo $pref ?>images/<?php echo $subitem['rollover']; ?>',1)" onmouseout="MM_swapImgRestore()"> <img src="<?php echo $pref ?>images/<?php echo ($pagename == $sectname)?$subitem['rollover']:$subitem['image']; ?>" alt="<?php echo $subitem['name']; ?>" id="<?php echo $imagename; ?>" /> </a></li> <?php } } } ?> <div id="pagetext"> <?php $pagefile = "includes/$filename.htm"; if (file_exists($pagefile)) { $text = file_get_contents($pagefile); echo($text); } else { ?> <?php } ?> <?php if($_POST['Submit'] == "Send") { ?> <h2>Thank you for your interest1</h2> <p>We will contact you shortly.</p> <?php // send email $gall = new GalleryXML(); $mailsubj = "Enquiry from ".$gall->gettitle(); $mailto = $gall->getemail(); $mailhead = "From: ".$_POST['email']; $mailbody = "Enquiry from ".$gall->gettitle()."\n"; $mailbody = $mailbody."Name: \t".$_POST['name']."\n"; $mailbody = $mailbody."Phone: \t".$_POST['phone']."\n"; $mailbody = $mailbody."Email: \t".$_POST['email']."\n"; $mailbody = $mailbody."Message: \t".$_POST['message']."\n"; if ($debug) printf("Email message<br>To: %s<br>Subj: %s<br>Email body: %s<br> Header: %s<br>", $mailto, $mailsubj, $mailbody, $mailhead); mail($mailto, $mailsubj, $mailbody, $mailhead); } ?> <table width="50%"> <form action="<?php echo($PHP_SELF)?>" method="post" enctype="multipart/form-data" name="contactform" onSubmit="RGB_validateForm('name','','R','phone','','RisPhone','email','','RisEmail');return document.MM_returnValue"> <tr> <th scope="row">Name</th> <td><input name="name" type="text" id="name" size="32"></td> </tr> <tr> <th scope="row">Telephone</th> <td><input name="phone" type="text" id="phone" size="24"></td> </tr> <tr> <th scope="row">Email</th> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <th scope="row">Message</th> <td><textarea name="message" cols="48" rows="6" id="message"></textarea> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" id="Submit" value="Send"> <input type="reset" name="Reset" id="Reset" value="Reset"> </tr> </form> </table> </div> <?php include("includes/footer.php"); ?> </body> </html>
-
I'm having a bit of trouble with a PHP contact form. There are issues with the error messages not showing on the form, the form not resetting, and the "name" input appearing as "X-AuthUser: XXX123 (which happens to be my FTP user name which I'm keeping private) when the email is sent to my gmail account. This is how the theme should look: http://pluto.html.themewoodmen.com/07-pluto-contact.html And this is what I have: http://divagraphics.us/test/contact.html The HTML <div class="contactForm"> <div class="successMessage alert alert-success alert-dismissable" style="display: none"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> Thank You! E-mail was sent. </div> <div class="errorMessage alert alert-danger alert-dismissable" style="display: none"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> Ups! An error occured. Please try again later. </div> <form class="liveForm" role="form" action="form/send.php" method="post" data-email-subject="Contact Form" data-show-errors="true" data-hide-form="false"> <fieldset> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="control-label">Name <span>(Required)</span></label> <input type="text" required name="name" class="form-control" id="name"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="control-label">Email <span>(Required)</span></label> <input type="email" required name="email" class="form-control" id="email"> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label class="control-label">Subject</label> <input type="text" name="subject" class="form-control" id="subject"> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label class="control-label">Message <span>(Required)</span></label> <textarea name="message" required class="form-control" rows="5" id="message"></textarea> </div> </div> </div> <input type="submit" class="btn btn-primary" value="Send Message"> </fieldset> </form> </div> The JS /** * Contact Form */ jQuery(document).ready(function ($) { "use strict"; $ = jQuery.noConflict(); var debug = false; //show system errors $('.liveForm').submit(function () { var $f = $(this); var showErrors = $f.attr('data-show-errors') == 'true'; var hideForm = $f.attr('data-hide-form') == 'true'; var emailSubject = $f.attr('data-email-subject'); var $submit = $f.find('[type="submit"]'); //prevent double click if ($submit.hasClass('disabled')) { return false; } $('[name="field[]"]', $f).each(function (key, e) { var $e = $(e); var p = $e.parent().find("label").text(); if (p) { var t = $e.attr('required') ? '[required]' : '[optional]'; var type = $e.attr('type') ? $e.attr('type') : 'unknown'; t = t + '[' + type + ']'; var n = $e.attr('name').replace('[]', '[' + p + ']'); n = n + t; $e.attr('data-previous-name', $e.attr('name')); $e.attr('name', n); } }); $submit.addClass('disabled'); $f.append('<input class="temp" type="hidden" name="email_subject" value="' + emailSubject + '">'); $.ajax({ url: $f.attr('action'), method: 'post', data: $f.serialize(), dataType: 'json', success: function (data) { $('span.error', $f).remove(); $('.error', $f).removeClass('error'); $('.form-group', $f).removeClass('has-error'); if (data.errors) { $.each(data.errors, function (i, k) { var input = $('[name^="' + i + '"]', $f).addClass('error'); if (showErrors) { input.after('<span class="error help-block">' + k + '</span>'); } if (input.parent('.form-group')) { input.parent('.form-group').addClass('has-error'); } }); } else { var item = data.success ? '.successMessage' : '.errorMessage'; if (hideForm) { $f.fadeOut(function () { $f.parent().find(item).show(); }); } else { $f.parent().find(item).fadeIn(); $f[0].reset(); } } $submit.removeClass('disabled'); cleanupForm($f); }, error: function (data) { if (debug) { alert(data.responseText); } $submit.removeClass('disabled'); cleanupForm($f); } }); return false; }); function cleanupForm($f) { $f.find('.temp').remove(); $f.find('[data-previous-name]').each(function () { var $e = jQuery(this); $e.attr('name', $e.attr('data-previous-name')); $e.removeAttr('data-previous-name'); }); } }); The PHP <?php // Contact subject $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = "divagraphicsinc@gmail.com"; $from = $_POST['email']; $headers = "From: $from"; mail($to,$subject,$message,$headers) ?>
- 2 replies
-
- php
- contact form
-
(and 3 more)
Tagged with:
-
I've built my website off of a template and have everything working except for the contact form. When I test the form and fill it out, it sends the email through to me except the content doesn't all send. I receive messages that say... Email = name@email.com Name = First Last Phone = 123-456-7890 Message = Email = name@email.com Name = First Last Phone = 123-456-7890 To sum it up, instead of a subject line only an email address is shown and more importantly the message section only displays an email. Below is all of the code I have associated with the form, I was looking for somewhere where message=email but failed to find it. Any help is greatly appreciated. PHP <?php $send_email_to = "name@email.com"; function send_email($name,$email,$phone,$subject,$message) { global $send_email_to; if($message=='message')$message=''; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= "From: ".$email. "\r\n"; $message = "<strong>Email = </strong>".$email."<br>"; $message .= "<strong>Name = </strong>".$name."<br>"; $message .= "<strong>Phone = </strong>".$phone."<br>"; $message .= "<strong>Message = </strong>".$message."<br>"; @mail($send_email_to, $subject, $message,$headers); return true; } function validate($name,$email,$phone,$message,$subject) { $return_array = array(); $return_array['success'] = '1'; $return_array['name_msg'] = ''; $return_array['email_msg'] = ''; $return_array['phone_msg'] = ''; $return_array['message_msg'] = ''; $return_array['subject_msg'] = ''; if($email == '') { $return_array['success'] = '0'; $return_array['email_msg'] = 'email is required'; } else { $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $return_array['success'] = '0'; $return_array['email_msg'] = 'Enter valid email.'; } } if($name == '') { $return_array['success'] = '0'; $return_array['name_msg'] = 'Name is required'; } else { $string_exp = "/^[A-Za-z .'-]+$/"; if (!preg_match($string_exp, $name)) { $return_array['success'] = '0'; $return_array['name_msg'] = 'Enter valid Name.'; } } if($subject == '') { $return_array['success'] = '0'; $return_array['subject_msg'] = 'Subject is required'; } if($message == '') { $return_array['success'] = '0'; $return_array['message_msg'] = 'Message is required'; } else { if (strlen($message) < 2) { $return_array['success'] = '0'; $return_array['message_msg'] = 'Enter valid Message.'; } } return $return_array; } $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $message = $_POST['message']; $subject = $_POST['subject']; $return_array = validate($name,$email,$phone,$message,$subject); if($return_array['success'] == '1') { send_email($name,$email,$phone,$subject,$message); } header('Content-type: text/json'); echo json_encode($return_array); die(); ?> HTML <article class="grid_12"> <h2>Contact Me</h2> <p>Use the form to send me an email and I should get back to you within 24 hours. <br> Or if you <i>really</i> need to talk to me give me a call, I'd love to hear from you. My number's listed below.<br><br></p> <form action="#" method="post" id="cform" name="cform"> <ul id="homehireus" class="hireform contactform"> <li> <label>Name:<span class="required">*</span></label> <input name="name" id="name" type="text" value="" tabindex="1"> </li> <li> <label>Email:<span class="required">*</span></label> <input name="email" id="email" type="text" value="" tabindex="2"> </li> <li> <label>Subject:<span class="required">*</span></label> <input name="subject" id="subject" type="text" value="" tabindex="4"> </li> <li> <label>Phone:<span class="required">*</span></label> <input name="phone" id="phone" type="text" value="" tabindex="3" placeholder="867-5309" > </li> <li> <label>Message:<span class="required">*</span></label> <textarea name="message" id="message" value="" tabindex="5"></textarea> </li> <li> <input type="button" id="send-message" value="Tell Me What You're Thinking" tabindex="6"> <div id="output" class="contactpage-msg"></div> </li> </ul> </form> </article> Java $(document).ready(function () { $('div#output').hide(); //bind send message here $('#send-message').click(sendMessage); $('button.close').live('click', function () { $(this).parent().find('p').html(''); $(this).parent().hide(); }); }); /* Contact Form */ function checkEmail(email) { var check = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/; if (!check.test(email)) { return false; } return true; } function sendMessage() { // receive the provided data var name = $("input#name").val(); var email = $("input#email").val(); var subject = $("input#subject").val(); var phone = $("input#phone").val(); var message = $("textarea#message").val(); message = 'message'; // check if all the fields are filled if (name == '' || phone == '' || email == '' || subject == '' || message == '') { $("div#output").show().html('<button type="button" class="close" data-dismiss="alert-close">x</button><p class="alert-close">You must enter all the fields!</p>'); return false; } // verify the email address if (!checkEmail(email)) { $("div#output").show().html('<button type="button" class="close" data-dismiss="alert">x</button><p>Please enter a valid Email Address</p>'); return false; } // make the AJAX request var dataString = $('#cform').serialize(); $.ajax({ type: "POST", url: 'contact.php', data: dataString, dataType: 'json', success: function (data) { if (data.success == 0) { var errors = '<ul><li>'; if (data.name_msg != '') errors += data.name_msg + '</li>'; if (data.email_msg != '') errors += '<li>' + data.email_msg + '</li>'; if (data.phone_msg != '') errors += '<li>' + data.phone_msg + '</li>'; if (data.message_msg != '') errors += '<li>' + data.message_msg + '</li>'; if (data.subject_msg != '') errors += '<li>' + data.subject_msg + '</li>'; $("div#output").removeClass('alert-success').addClass('alert-error').show().html('<button type="button" class="close" data-dismiss="alert">x</button><p> Could not complete your request. See the errors below!</p>' + errors); } else if (data.success == 1) { $("div#output").removeClass('alert-error').addClass('alert-success').show().html('<button type="button" class="close" data-dismiss="alert">x</button><p>You message has been sent successfully!</p>'); } }, error: function (error) { $("div#output").removeClass('alert-success').addClass('alert-error').show().html('<button type="button" class="close" data-dismiss="alert">x</button><p> Could not complete your request. See the error below!</p>' + error.statusText); } }); return false; }
- 4 replies
-
- php
- contact form
-
(and 2 more)
Tagged with:
-
Hello, I am trying to get a little contact form working with a bootstrap 3 theme, but the data is not being sent to my email. If anyone can spot anything obvious as to why its not working (or any ways to make this code much better), I would really appreciate it. <?php if (isset($_POST['submit'])) { $to = 'myemail@email.com'; $subject = "WEBSITE ENQUIRY"; $name_field = $_POST['name']; $email_field = $_POST['email']; $phone_field = $_POST['phone']; $message = $_POST['message']; if (strlen(trim($message)) > 0) { $body = "From: $name_field \n E-Mail: $email_field \n Phone: $phone_field \n Message: $message \n "; if (mail($to, $subject, $body)) { echo "<h3>Thanks! Your email has been sent. <br />I will answer your enquiry as soon as possible.</h3> <hr>"; } else { echo 'Cannot sent mail'; } } else { echo "<h4>Failed to Send Mail. <br><br>Please ensure that all fields are filled out in order to email us.</h4><hr>"; } } ?> <div class="col-sm-8"> <p>If you wish to ask a question about a potential project please get in touch via the form below, or from the details on the right.</p> <form role="form" method="POST" action="contact.php"> <div class="row"> <div class="form-group col-md-12"> <label for="Name">Name</label> <input type="text" name="name" class="form-control" id="input1"> </div> <div class="form-group col-md-12"> <label for="Email">Email Address</label> <input type="email" name="email" class="form-control" id="input2"> </div> <div class="form-group col-md-12"> <label for="Phone">Phone Number</label> <input type="phone" name="phone" class="form-control" id="input3"> </div> <div class="clearfix"></div> <div class="form-group col-lg-12"> <label for="Message">Message</label> <textarea name="message" class="form-control" rows="6" id="input4"></textarea> </div> <div class="form-group col-lg-12"> <input type="hidden" name="save" value="contact"> <button type="submit" class="btn btn-primary pull-right">Submit</button> <div class="clearfix"></div> </div> </div> </form>
-
I've made a web site (for a client) that has a contact form. The form works fine, but the email that arrives shows a long weird address, which I assume is the hosting server name: Visitor@p3nlhgxxxxxxxxxsecureserver.net. These emails look scary to my website client, and she's afraid to open them. Is there some code I can add to the php file that will change who the email appears to be from in my client's inbox? This is part of what's in the php file: $EmailFrom = "Visitor"; $EmailTo = "MyClient@HerAddress.com"; $Subject = "Message from BusinessName website"; $Name = Trim(stripslashes($_POST['Name'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); Disclaimer . . . I know nothing about writing PHP. TIA - gardencat
-
Hello all, New to php and this website, just started with trying to create a contact form as my first project, all seemed to be going well until I put the form online. When the form is filled in, it does no keep the data put into the form rather it send me a email like the example below: Name: name Email :email Comments: comments I have try and research all I can but now I'm running out of energy on this, if any experienced phpfreaks (pun intended) could help me by looking over my code I would be very grateful for any advice given. Many thanks in advance Jeff. <?php $errors = array(); $missing = array(); if (isset ($_POST['send'])) { $to = 'myemail'; $subject = 'Feedback from contact form'; $expected = array('name', 'email', 'comments'); $required = array('name', 'email', 'comments'); $headers = "From: \r\n"; $headers .= "Content-type: text/plain: charset=utf-8"; $authenticate = '-myemail'; require './mailprocess.php'; if ($mailSent) { header('Location:thankyou.php'); exit; } } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Contact Form</title> </head> <body> <h1>Contact Form</h1> <?php if (($_POST && $suspect) || ($_POST && isset($errors['mailfail']))) { ?> <p class="warning"> Your mail was not sent.</p> <?php } elseif ($errors || $missing) { ?> <p class="warning"> Please fix highlighted item(s).</p> <?php }?> <form name="contact" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p> <label for="name">Name: <?php if ($missing && in_array('name', $missing)) { ?> <span class="warning">Please enter your name</span> <?php } ?> </label> <input type="text" name="name" id="name" <?php if ($errors || $missing) { echo 'value="' . htmlentities($name, ENT_COMPAT, 'utf-8') . '"'; } ?> > </p> <p> <label for="email">Email: <?php if ($missing && in_array('email', $missing)) { ?> <span class="warning">Please enter your email address</span> </label> <?php } elseif (isset ($errors['email'])) { ?> <span class="warning">Invalid email address</span> <?php } ?> <input type="text" name="email" id="email" <?php if ($errors || $missing) { echo 'value="' . htmlentities($email, ENT_COMPAT, 'utf-8') . '"'; } ?> > </p> <p> <label for="comments">Message: <?php if ($missing && in_array('comments', $missing)) { ?> <span class="warning">Please enter your message</span> <?php } ?> </label> <textarea name="comments" id="comments"><?php if ($errors || $missing) { echo htmlentities($comments, ENT_COMPAT, 'utf-8'); } ?></textarea> </p> <p> <input type="submit" name="send" id="send" value="Send Message"> </p> </form> </body> </html> And the mail process code is below here : <?php $suspect = false; $pattern = '/Content-Type:|Bcc:|Cc:/i'; function isSuspect($val, $pattern, &$suspect) { if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { if (preg_match($pattern, $val)) { $suspect = true; } } } isSuspect($_POST, $pattern, $suspect); if (!$suspect) { foreach ($_POST as $key => $value) { $temp = is_array($value) ? $value :trim($value); if (empty($temp) && in_array($key, $required)) { $missing[] = $key; $$key = ''; } elseif(in_array($key, $expected)) { $$key = $temp; } } } if (!$suspect && !empty($email)) { $validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if ($validemail) { $headers .= "\r\nReply-to: $validemail"; } else { $errors['email'] = true; } } if (!$suspect && !$missing && !$errors) { $message = ''; foreach ($expected as $item) { if (isset($$item) && !empty($$item)) { $val = $item; } else { $val = 'Not selected'; } if (is_array($val)) { $val = implode(', ', $val); } $item = str_replace(array('_', '-'), ' ', $item); $message .= ucfirst($item) . ": $val\r\n\r\n"; } $message = wordwrap($message, 70); $mailSent = mail($to, $subject, $message, $headers, $authenticate); if (!$mailSent) { $errors['mailfail'] = true; } }
-
Hello guys, I'm very new to everything that has to do with PHP. I started exploring it a while ago and at the moment I'm working on a contact form. I am using the following script that I found on this website: http://www.freecontactform.com/email_form.php PHP <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "you@yourdomain.com"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> HTML <form name="contactform" method="post" action="send_form_email.php"> <table width="450px"> <tr> <td valign="top"> <label for="first_name">First Name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top""> <label for="last_name">Last Name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email">Email Address *</label> </td> <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="telephone">Telephone Number</label> </td> <td valign="top"> <input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="comments">Comments *</label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> <a href="http://www.freecontactform.com/email_form.php">Email Form</a> </td> </tr> </table> </form> Now i want to implement the possibility to send a file as an attachment in the email that gets send to email adres x. For certain reasons i really don't want to change script. I only want to make it function to temporary upload a file, store it as attachment and send it. All tips, tricks or sollutions are ofcourse more then welcome.
-
Hello ! I am sure there is more than one smart freak around here that is awesome enough to figure out the solution for my challenge here. So I have a contact form and events on my website that I promote via other people also (affiliates). People come chose event, put name, email, telefon and promotional CODE (actually affiliate code) aff1, aff2 etc. At this point the form sends out an email to me for each registration. How can I make the form send out an email to the affiliate also when a user inserts his affiliate code in the CODE input box ? So one mail comes to me and automaticly one goes to the affiliate. I think at two different solutions - either with database or not. A. database In my database I have one colum with affiliate codes and next one with their email address. The form searches for a match in database for code entered and if finds a match it send a copy of form submission to the email address associated with the affiliate code it found. B. using IF IF input_affcode = 001 then sendmail to aff1@yahoo.com IF input_affcode = 002 then send mail to aff2@gmail.com etc. Now I don't know how to do that in coding Please help me out. For this moment I am using SIMFATIC forms and I would like to have this small function implemented to the code....otherwise it works very well. This is from main code...my thought is to condition the autoresponder to send depending on the code it finds in the input field. $data_email_sender = new FM_FormDataSender(sfm_readfile("./templ/contactus_email_subj.txt"),sfm_readfile("./templ/contactus_email_body.txt"),"%email_f%"); $data_email_sender->AddToAddr("office@universulsacru.ro"); $formmailobj->addModule($data_email_sender); $autoresp = new FM_AutoResponseSender(sfm_readfile("./templ/LP_inregistrare_resp_subj.txt"),sfm_readfile("./templ/LP_inregistrare_resp_body.txt")); $autoresp->SetToVariables("numeprenume_f","email_f"); $formmailobj->addModule($autoresp); All the best to you! Andrei Stefan
-
- contact form
- php
-
(and 3 more)
Tagged with: