YST Posted July 17, 2014 Share Posted July 17, 2014 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(); } } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 17, 2014 Share Posted July 17, 2014 Uhhhh.... Just use your php skills and make those changes? Quote Link to comment Share on other sites More sharing options...
Stefany93 Posted July 17, 2014 Share Posted July 17, 2014 ^^ The collegue is right, make the changes yourself and when you get stuck, ask us to help you with a spesific problem. Otherwise you will never learn. If of course, you wanna learn PHP. If you don't, then I'd suggest you pay someone to help you. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.