[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

PHP Contact form

Asked by demazter in PHP Scripting Language, Scripting Languages

Tags: PHP

Hi All,
I have a client who has recently employed a web developer to create a website for them.
They have their website up and running and have come to me (their IT Support Guy) to find out why something on their website isn't working.

Long story short, web developer no longer on the scene and they just want little tweeks done to their website which I am happy to do.  however I am not familiar with PHP at all, I did some ASP database work about 5 yeas ago and even did a Microsoft Visual Interdev course but this I don't know.

Basically the form seems to work but it doesn't submit the message part, I have done a bit of fiddling but cannot get it to work.  Below is the code
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
<?php
 
isset($_POST['enquirytype']) ? $enquirytype = $_POST['enquirytype'] : $enquirytype = '';
isset($_POST['firstname']) ? $firstname = $_POST['firstname'] : $firstname = '';
isset($_POST['surname']) ? $surname = $_POST['surname'] : $surname = '';
isset($_POST['wpmmail']) ? $wpmmail = $_POST['wpmmail'] : $wpmmail = '';
 
if ($_POST) {
  function validate() { // validates input fields from the form
    global $msg;
    foreach (array("enquirytype","firstname","surname","wpmmail") as $req_field) {
	  	if ($_POST["enquirytype"] =="") {
		$msg = "Please select an enquiry type";
		return false;
	  }
	  	if ($_POST["firstname"] =="") {
		$msg = "Please enter your firstname";
		return false;
	  }
	  	if ($_POST["surname"] =="") {
		$msg = "Please enter your surname";
		return false;
	  }
	  	if ($_POST["wpmmail"] =="") {
		$msg = "Please enter a valid email address";
		return false;
 
	  } }
	return true;
  }
  // temp fix to spam problem....
  if (stristr($wpmmail, "maildomain.com")) {
die("Sorry invalid email. Please press back button and try again.");
}
  if (stristr($firstname, "maildomain.com")) {
die("Sorry invalid name. Please press back button and try again.");
}
  function safe( $name ) {
   return( str_replace(array( "\\r", "\\n", "%0A", "%0a", "%0D", "%0d", "Content-Type:", "BCC:", "bcc:" ), "", $name ) );
}
//....to here
 
  if (validate()) { // if all input fields are valid
		$headers = "From: enquiries@maildomain.com\r\n";
		$headers .= "Reply-To: $wpmmail\r\n";
		$headers .= "MIME-Version: 1.0\r\n"; 
		$headers .= "X-Sender: $henmail\r\n"; 
		$headers .= "X-Mailer: PHP4\r\n"; //mailer 
		$headers .= "X-Priority: 1\r\n"; //1 UrgentMessage, 3 Normal 
		$headers .= "Return-Path: $to\r\n";
		// define the from address for the email response
		$to = "mailrecipient@maildomain.co.uk";
		// define text for the body of the email response
	  $e_body.= "Name............................: $firstname $surname\n";
	  $e_body.= "Address.........................: $address1\n";
	  $e_body.= "                                  $address2\n";
	  $e_body.= "                                  $citytown\n";
	  $e_body.= "                                  $county\n";
	  $e_body.= "                                  $postcode\n";
	  $e_body.= "Telephone/Mobile................: $phone\n";
	  $e_body.= "Email...........................: $wpmmail\n";
    $e_body.= "Message:                        : $message\n";
	  $e_body.= "$message\n";
	  $e_body.= "$enquirytype,$firstname,$surname,$address1,$address2,$citytown,$county,$county,$postcode,$phone,$wpmmail,$message";
	  // send response to client
	  mail($to,"Website Enquiry","The following entry was submitted from the website:\n\n" . $e_body, $headers);
	 // mail($e_cc,"Free bale entry","The following entry was submitted from the website:\n\n" . $e_body, $headers);
	  // redirect to thank you page
	  header("Location: thanks.php?firstname=" .$firstname);
    }
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php include('../includes/meta.php'); ?>
</head>
<body>
<?php include('../includes/header.php'); ?>
<div id="wrap">
  <div id="content">
<?php include('../includes/tenant-subnav.php'); ?>
    <div id="mainwide">
      <h2>Enquiries</h2>
      <p>Please choose the type of query you have and then complete your personal details, before entering your query in the text box at the bottom of the form.</p>
      <div class="application">
<form action="" method="post" name="form1" id="form1" onsubmit="return validate('enquirytype','firstname','surname','wpmmail')">
        <p class="alert">
          <?php if ($msg) { ?>
          <?php echo $msg ?>
          <?php } ?>
        </p>
                 <fieldset id="constructionline">
          <legend>Enquiry:</legend>
                    <div class="formcol1">
 
 <label for="enquirytype">Enquiry Type:*<strong></strong></label>
   <select name="enquirytype" tabindex="1" class="drop" id="enquirytype" >
    <option value="" selected="selected"<?php if ($_POST["referrer"] == "") {echo " selected";} ?>>Please select...</option>
    <option value="Repair"<?php if ($_POST["enquirytype"] == "Repair") {echo " selected";} ?>>Repair</option>
    <option value="Rent"<?php if ($_POST["enquirytype"] == "Rent") {echo " selected";} ?>>Rent</option>
    <option value="Other"<?php if ($_POST["enquirytype"] == "Other") {echo " selected";} ?>>Other</option>
  </select>
        <br />
        <label for="firstname">First name:*<strong></strong></label>
        <input type="text" id="firstname" tabindex="2" name="firstname" value="<?php if(isset($_POST['firstname'])) echo $_POST['firstname'] ?>"/>
        <br />
        <label for="surname">Surname:*<strong></strong></label>
        <input type="text" id="surname" tabindex="3" name="surname" value="<?php if(isset($_POST['surname'])) echo $_POST['surname'] ?>"/>
        <br />
        <label for="wpmmail">Email:<strong></strong></label>
        <input type="text" name="wpmmail" id="wpmmail" tabindex="4" value="<?php if(isset($_POST['wpmmail'])) echo $_POST['wpmmail'] ?>" />
        <br />
        <label for="address1">Address:<strong></strong></label>
        <input type="text" name="address1" tabindex="5" id="address1" value="<?php if(isset($_POST['address1'])) echo $_POST['address1'] ?>" />
        <br />
        <label for="address2">&nbsp;</label>
        <input type="text" name="address2" tabindex="6" id="address2" value="<?php if(isset($_POST['address2'])) echo $_POST['address2'] ?>" />
        <br />
        <label for="citytown">City/Town:</label>
        <input type="text" name="citytown" tabindex="7" id="citytown" value="<?php if(isset($_POST['citytown'])) echo $_POST['citytown'] ?>" />
        <br />
        <label for="county">County:<strong></strong></label>
        <input type="text" name="county" tabindex="8" id="county" value="<?php if(isset($_POST['county'])) echo $_POST['county'] ?>" />
        <br />
        <label for="postcode">Postcode:</label>
        <input type="text" name="postcode" tabindex="9" id="postcode" value="<?php if(isset($_POST['postcode'])) echo $_POST['postcode'] ?>" />
        <br />
        <label for="phone">Telephone/Mobile:<strong></strong></label>
        <input type="text" name="phone" tabindex="9" id="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'] ?>" />
        <br />
        </div>
        
        <div class="formcol1">
 
        <label for="message">Message:</label><br />
        <textarea name="message" rows="4" cols="40" tabindex="9"><?php if(isset($_POST['message'])) echo $_POST['message'] ?></textarea>
        </div>
        <p>
          <input type="submit" name="button" id="button" value="Submit" />
          
        </p>
        </fieldset>
      </form>
      </div>
    </div>
    </div>
</div>
<?php include('../includes/footer.php'); ?>
</body>
</html>
[+][-]07/20/09 11:54 AM, ID: 24897826Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP Scripting Language, Scripting Languages
Tags: PHP
Sign Up Now!
Solution Provided By: jausions
Participating Experts: 2
Solution Grade: A
 
[+][-]07/20/09 12:13 PM, ID: 24898000Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625