Jump to content

Can't get message to desplay when sending a form through email


hoodie

Recommended Posts

<?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 = '?????@a????????.com';

$subject = 'Customers MLS INFO';

// list expected fields

  $expected = array('firstname', 'middlename', 'lastname');

  // set required fields

  $required = array('firstname', 'middlename', 'lastname');

  // 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;

        }

  }

}

  // go ahead only if not suspsect and all required fields OK

  if (!$suspect && empty($missing)) {

 

 

//build the message

$message = "First Name $firstname\n\n";

$message .= "Middle Name $middlename\n\n";

$message .= "Last Name $lastname\n\n";

//limit line length to 70 characters

$message = wordwrap(message, 70);

//send it

$mailSent = mail($to, $subject, $message);

if ($mailSent) {

      // $missing is no longer needed if the email is sent, so unset it

      unset($missing);

      }

}

  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.