Jump to content

modification of contact form


YST

Recommended Posts

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();
}
}

?>

Link to comment
Share on other sites

^^ 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.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.