webkrios 0 Newbie Poster

Hi,

I have created a form and have successfully sent it to my email address. However, not all of the "message" comes through in the email. The only part of the message that comes through is the "contact" part. Can you please help?? I thank you very much in advance! :)

Here is my code:

<?php
if (array_key_exists('send', $_POST)) {
  //mail processing script
  // remove escape characters from POST array
  if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value) {
      $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
      return $value;
      }
    $_POST = array_map('stripslashes_deep', $_POST);
    }
  
  $to = 'kyle.xxxx@xxxx.com'; // use your own email address
  $subject = 'Hawaii Real Estate Lead - Dream Home Finder';
  
  // list expected fields
  $expected = array('fname', 'lname', 'pnumber', 'email', 'contact');
  // set required fields
  $required = array('fname', 'lname', 'pnumber', 'email');
  // create empty array for any missing fields
  $missing = array();
  
  // assume that there is nothing suspect
  $suspect = false;
  // create a pattern to locate suspect phrases
  $pattern = '/Content-Type:|Bcc:|Cc:/i';
  
  // function to check for suspect phrases
  function isSuspect($val, $pattern, &$suspect) {
    // if the variable is an array, loop through each element
	// and pass it recursively back to the same function
	if (is_array($val)) {
      foreach ($val as $item) {
	    isSuspect($item, $pattern, $suspect);
	    }
	  }
    else {
      // if one of the suspect phrases is found, set Boolean to true
	  if (preg_match($pattern, $val)) {
        $suspect = true;
	    }
	  }
    }

  // check the $_POST array and any subarrays for suspect content
  isSuspect($_POST, $pattern, $suspect);
  
  if ($suspect) {
    $mailSent = false;
	unset($missing);
	}
  else {
    // process the $_POST variables
    foreach ($_POST as $key => $value) {
      // assign to temporary variable and strip whitespace if not an array
      $temp = is_array($value) ? $value : trim($value);
      // if empty and required, add to $missing array
      if (empty($temp) && in_array($key, $required)) {
        array_push($missing, $key);
        }
      // otherwise, assign to a variable of the same name as $key
      elseif (in_array($key, $expected)) {
        ${$key} = $temp;
        }
      }  
    }
	
  // validate the email address
  if (!empty($email)) {
    // regex to identify illegal characters in email address
    $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
	// reject the email address if it deosn't match
	if (!preg_match($checkEmail, $email)) {
	  $suspect = true;
	  $mailSent = false;
	  unset($missing);
	  }
	}
  
  // go ahead only if not suspsect and all required fields OK
  if (!$suspect && empty($missing)) {
   
	
    // build the message
    $message = "First Name: $fname\n\n";
	$message = "Last Name: $lname\n\n";
	$message = "Phone Number: $pnumber\n\n";
    $message = "Email: $email\n\n";
	$message = "Best time to contact: $contact\n\n";
	

    // limit line length to 70 characters
    $message = wordwrap($message, 70);

    // create additional headers
	$headers = 'From: [email]webmaster@xxxxxx.com[/email]';
	if (!empty($email)) {
	  $headers .= "\r\nReply-To: $email";
	  }
	
    // send it  
    $mailSent = mail($to, $subject, $message, $headers);
	  if ($mailSent) {
      // $missing is no longer needed if the email is sent, so unset it
      unset($missing);
      }
	}
  }
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact form</title>
<link href="file:///C|/Documents and Settings/Trudy Walker/Desktop/examples/styles/contact.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Dream Home Finder</h1>
<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>
  <p class="warning">Please complete the missing item(s) indicated.</p>

<?php
  }
elseif ($_POST && !$mailSent) {
?>
  <p class="warning">Sorry, there was a problem sending your message. 
Please try later.</p>
<?php
  }
elseif ($_POST && $mailSent) {
?>
  <p><strong>Your message has been sent. Thank you for your feedback.
</strong></p>
<?php } ?>
<p>We welcome feedback from visitors to our site. Please use the following form to let us know what you think about it.</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">
    <fieldset>
    <legend>Your details</legend>
    <p>
        <label for="fname">First Name: <?php
        if (isset($missing) && in_array('fname', $missing)) { ?>
          <span class="warning">Please enter your first name</span><?php } ?>
        </label>
        <input name="fname" type="text" class="textInput" id="fname" 
        <?php if (isset($missing)) {
		  echo 'value="'.htmlentities($_POST['fname']).'"';
		  } ?>
        />
    </p>
    <p>
        <label for="lname">Last Name: <?php
        if (isset($missing) && in_array('lname', $missing)) { ?>
          <span class="warning">Please enter your last name</span><?php } ?>
        </label>
        <input name="lname" type="text" class="textInput" id="lname" 
        <?php if (isset($missing)) {
		  echo 'value="'.htmlentities($_POST['lname']).'"';
		  } ?>
        />
    </p>
    <p>
        <label for="pnumber">Phone Number: <?php
        if (isset($missing) && in_array('pnumber', $missing)) { ?>
          <span class="warning">Please enter your phone number</span><?php } ?>
        </label>
        <input name="pnumber" type="text" class="textInput" id="pnumber" 
        <?php if (isset($missing)) {
		  echo 'value="'.htmlentities($_POST['pnumber']).'"';
		  } ?>
        />
    </p>
    <p>
        <label for="email">Email: <?php
        if (isset($missing) && in_array('email', $missing)) { ?>
          <span class="warning">Please enter your email address</span><?php } ?>
        </label>
      <input name="email" type="text" class="textInput" id="email"
      <?php if (isset($missing)) {
		  echo 'value="'.htmlentities($_POST['email']).'"';
		  } ?>
      />
    </p>
  <p>
        <label for="contact">Best time to contact you:</label>
      <input name="contact" type="text" class="textInput" id="contact"
      <?php if (isset($missing)) {
		  echo 'value="'.htmlentities($_POST['contact']).'"';
		  } ?>
      />
    </p>
    </div>
    <p>&nbsp;</p>
    <p class="clearIt">
        <input type="submit" name="send" id="send" value="Send comments" />
    </p>
    </fieldset>
</form>
</body>
</html>