电邮表格数据

时间:2013-05-23 18:52:39

标签: php forms email

我有一个大型表单,我想从中收集数据并将其输入MySQL数据库并将结果通过电子邮件发送给我自己。我到目前为止的代码输入数据就好了。我也正在使用表单上传多个文件,并且工作得很好。这是电子邮件部分我不知道它为什么不起作用。我是php编码的新手,所以我不知道这是我的电子邮件代码还是我的php代码中的电子邮件代码。有什么建议或帮助吗?

这是我的所有PHP代码:

<?php require_once('Connections/ms_orders.php'); ?>


<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["notsure_insert"])) && ($_POST["notsure_insert"] == "notSureForm")) {
  $insertSQL = sprintf("INSERT INTO `order` (firstName, lastName, division, phone, email, quantity, dateNeeded, itemType, jobDescription) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['division'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['quantity'], "text"),
                       GetSQLValueString($_POST['dateNeeded'], "text"),
                       GetSQLValueString($_POST['itemType'], "text"),
                       GetSQLValueString($_POST['jobDescription'], "text"));

  mysql_select_db($database_ms_orders, $ms_orders);
  $Result1 = mysql_query($insertSQL, $ms_orders) or die(mysql_error());

  $insertGoTo = "_finished/notsure_finish.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));



/* FILE UPLOAD CODE */
{
    $number_of_file_fields = 0;
    $number_of_uploaded_files = 0;
    $number_of_moved_files = 0;
    $uploaded_files = array();
    $upload_directory = dirname(__file__) . '/uploads/'; //set upload directory
    /**
     * we get a $_FILES['images'] array ,
     * we procee this array while iterating with simple for loop
     * you can check this array by print_r($_FILES['images']);
     */
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
        $number_of_file_fields++;
        if ($_FILES['file']['name'][$i] != '') { //check if file field empty or not
            $number_of_uploaded_files++;
            $uploaded_files[] = $_FILES['file']['name'][$i];
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $upload_directory . $_FILES['file']['name'][$i])) {
                $number_of_moved_files++;
            }

        }

    }

}
/* END FILE UPLOAD CODE */

/* EMAIL CODE */
{
    $to = 'mjc7475@gmail.com';
    $subject = 'Not Sure Where to Begin';
    $firstNameField = $_POST['firstName'];
    $lasttNameField = $_POST['lastName'];
    $divisionField = $_POST['division'];
    $phoneField = $_POST['phone'];
    $emailField = $_POST['email'];
    $itemTypeField = $_POST['itemType'];
    $jobDescriptionField = $_POST['jobDescription'];
    $fileField = $_POST['file'];
    $dateNeededField = $_POST['dateNeeded'];
    $quantityField = $_POST['quantity'];
    $body = <<<EOD
<strong>Name:</strong> <br>
$firstName $lasttName <br>
<strong>Division:</strong> <br>
$division <br>
<strong>Phone:</strong> <br>
$phone <br>
<strong>Email:</strong> <br>
$email <br>
<strong>Item Type:</strong> <br>
$itemType <br>
<strong>Job Description:</strong><br>
$jobDescription <br>
<strong>File(s) Uploaded:</strong> <br>
$file <br>
<strong>Date Needed:</strong> <br>
$dateNeeded <br>
<strong>Quantity Nedded:</strong> <br>
$quantity <br>
EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $headers .= "Reply-To: $email\r\n";
    mail($to, $subject, $body, $headers);
}
/* END EMAIL CODE */



}

?>

0 个答案:

没有答案