Page 1 of 1

Issues with emailing a form (Now with shorter piece of code)

Posted: Wed Apr 02, 2008 7:27 pm
by ggrant3
I have created an order form and most of it works fine.

However, I noticed that the fields that are not "required" to be filled out by the user, are not being included into the email message that is sent to me.

Also, the radio buttons that I have listed need to be a required portion of the form, but I can't seem to figure out how to do that.

Can you guys see what I am missing or did wrong to cause those two issues? BTW, I still consider myself a newb when it comes to php, so if it something basic don't kill me :)

Code: Select all

<?php include('includes/title.inc.php');
 ?>
<?php
include('includes/corefuncs.php');
if (function_exists('nukeMagicQuotes')) {
    nukeMagicQuotes();
    }
    
  
    
// Process the email
if (array_key_exists('send', $_POST)) {
//create session
####################################################################
# THE SESSION MUST START BEFORE YOU CAN CREATE $_SESSION VARIABLES #
####################################################################
session_start();
 
 
    
// List expected fields
    $expected = array('quantity', 'shipping', 
'billingfirstname', 'billinglastname', 'cardtype', 
'creditcardnumber', 'expmonth', 'expyear', 'cvv', 
'billingaddress1','billingaddress2', 'billingcity', 
'billingstate', 'billingpostalcode', 'email', 
'billingphonenumber', 'shippingfirstname', 
'shippinglastname', 'shippingaddress1', 
'shippingaddress2', 'shippingcity', 'shippingstate', 
'shippingpostalcode', 'shippingphonenumber', 'comments');
    
// Set required fields
    $required = array('quantity', 'shipping', 
'billingfirstname', 'billinglastname', 'cardtype', 
'creditcardnumber', 'expmonth', 'expyear', 'cvv', 
'billingaddress1', 'billingcity', 'billingstate', 
'billingpostalcode', 'email', 'shippingfirstname', 
'shippinglastname', 'shippingaddress1', 
'shippingcity', 'shippingstate', 'shippingpostalcode');
    
// 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 in 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 ensure no illegal characters in email address
     $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
     // Regect the email address if it doesn't match
     if (!preg_match($checkEmail, $email)) {
        array_push($missing, 'email');
        }
    }
  
// Go ahead only if not suspect and all requried fields OK
    if (!$suspect && empty($missing)) { 
    
// set default values for variables that might not exist
    $quantity = isset($quantity) ? : 'Nothing selected';
 
####################################################################
# THE RECEIPT NUMBER SHOULD BE GENERATED ONLY AFTER THE FORM HAS   #
# BEEN SUBMITTED, SO IT MUST GO INSIDE THE CONDITIONAL BLOCK       #
####################################################################
  // get the contents of the text file
  $receipt = file_get_contents('receipt.txt');
  // break it into an array of parts
  $parts = explode('-', $receipt);
 
  if ($parts[0] != date('Y')) {
    $parts[0] = date('Y');
    $parts[1] = '0000';
    $parts[2] = '0000';
  }
 
  if ($parts[2] <= 9998) {
    $parts[2]++;
    $parts[2] = sprintf('%04d', $parts[2]);
  }
 
  else {
    $parts[2] = '0001';
    $parts[1]++;
    $parts[1] = sprintf('%04d', $parts[1]);
  }
 
   // rebuild the number and reassign to $receipt
  $receipt = implode('-', $parts);
  $file = fopen('receipt.txt', 'w');
  fwrite($file, $receipt);
  fclose($file);
  
// Receipt Number
$_SESSION['receipt'] = $receipt;
    $to = 'zzz@zzz.com'; // Use your own email address
    $subject = "$receipt";
 
 
// Build the message
$message = "Quantity: $quantity\n\n";
$message .= "Shipping: $shipping\n\n";
$message .= "Billing First Name: $billingfirstname\n\n";
$message .= "Billing Last Name: $billinglastname\n\n";
$message .= "Card Type: $cardtype\n\n";
$message .= "Credit Card Number: $creditcardnumber\n\n";
$message .= "Exp Month: $expmonth\n\n";
$message .= "Exp Year: $expyear\n\n";
$message .= "CVV: $cvv\n\n";
$message .= "Email: $email\n\n";
$message .= "Billing Address1: $billingaddress1\n\n";
$message .= "Billing Address2: $billingaddress2\n\n";
$message .= "Billing City: $billingcity\n\n";
$message .= "Billing State: $billingstate\n\n";
$message .= "Billing Postal Code: $billingpostalcode\n\n";
$message .= "Billing Phone Number: $billingphonenumber\n\n";
$message .= "Shipping First Name: $shippingfirstname\n\n";
$message .= "Shipping Last Name: $shippinglastname\n\n";
$message .= "Shipping Address1: $shippingaddress1\n\n";
$message .= "Shipping Address2: $shippingaddress2\n\n";
$message .= "Shipping City: $shippingcity\n\n";
$message .= "Shipping State: $shippingstate\n\n";
$message .= "Shipping Postal Code: $shippingpostalcode\n\n";
$message .= "Shipping Phone Number: $shippingphonenumber\n\n";
$message .= "Comments: $comments";
 
// Limit line length to 70 characters
$message = wordwrap($message, 70);
 
// Create additional headers
$additionalHeaders = "From: Order<zzz@zzz.com>\r\n";
 
$_SESSION['quantity'] = $quantity;
$_SESSION['shipping'] = $shipping;
$_SESSION['billingfirstname'] = $billingfirstname;
$_SESSION['billinglastname'] = $billinglastname;
$_SESSION['cardtype'] = $cardtype;
$_SESSION['creditcardnumber'] = $creditcardnumber;
$_SESSION['expmonth'] = $expmonth;
$_SESSION['expyear'] = $expyear;
$_SESSION['cvv'] = $cvv;
$_SESSION['email'] = $email;
$_SESSION['billingaddress1'] = $billingaddress1;
$_SESSION['billingaddress2'] = $billingaddress2;
$_SESSION['billingcity'] = $billingcity;
$_SESSION['billingstate'] = $billingstate;
$_SESSION['billingpostalcode'] = $billingpostalcode;
$_SESSION['phonenumber'] = $phonenumber;
$_SESSION['shippingfirstname'] = $shippingfirstname;
$_SESSION['shippinglastname'] = $shippinglastname;
$_SESSION['shippingaddress1'] = $shippingaddress1;
$_SESSION['shippingaddress2'] = $shippingaddress2;
$_SESSION['shippingcity'] = $shippingcity;
$_SESSION['shippingstate'] = $shippingstate;
$_SESSION['shippingpostalcode'] = $shippingpostalcode;
$_SESSION['shippingphonenumber'] = $shippingphonenumber;
$_SESSION['comments'] = $comments;
 
 
 
// Send it
$mailSent = mail($to, $subject, $message, $additionalHeaders);
if ($mailSent) {
// redirect the page with a fully qualified URL
    header('Location: orderconfirmation.php');
    exit;
}
}
}
    ?>
 
<!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=iso-8859-1" />
<title>zzz Order Page</title>
<link href="assets/stylesheet1.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
<!--
.style1 {
    font-size: 12px;
    font-weight: bold;
}
.style2 {font-weight: bold}
.style4 {color: #FF0000}
.style5 {font-size: 16px; font-weight: bold; }
.style6 {font-size: 16px; font-weight: bold; font-style: italic; }
.style7 {font-size: 12px}
 
-->
</style>
</head>
<body>
<div id="header">
<img src="images/zzzheader2.gif" width="600" height="150" /></div>
    <div id="orderpagepic1"><img src="images/zzzprices.gif" width="400" height="180" /></div>
    <div id="orderform">
<h1>Order Page</h1>
<?php include('includes/menu.inc.php'); ?>
<?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 again.</p>
    <?php
    }
    elseif ($_POST && $mailSent) {
    ?>
    <p><strong>Thank You for your order, you information information 
is being processed.  If you have any questions please contact us.</strong>
</p>
    <?php } ?>
    
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="500" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td height="31" colspan="3"><font size="1.5">(<font color="red">*</font> = a required field)</font></td>
    </tr>
  <tr>
    <td width="155" height="10" bgcolor="#F5F5F5">
    <fieldset id="quantity">
        <input name="quantity" type="radio" value="1 Bottle" id="1 bottle"
        <?php
        $OK = isset($_POST['quantity']) ? true : false;
        if ($OK && isset($missing) && $_POST['quantity'] == 'One Bottle $64.95') { ?>
        checked="checked"
        <?php } ?>
        />
        <label for="1 bottle"><span class="style7">1 Bottle $64.95</span></label>
        <br />
        <input name="quantity" type="radio" value="3 Bottles" id="3 bottles"
        <?php
        if ($OK && isset($missing) && $_POST['quantity'] == 'Three Bottles $129.90') { ?>
        checked="checked"
        <?php } ?>
        />
        <label for="3 bottles" class="style7">3 Bottles $129.90</label>
          </fieldset>   </td>
    <td height="10" bgcolor="#F5F5F5">
    <fieldset id="shipping">
    <input name="shipping" type="radio" value="USPS" id="USPS"
        <?php
        $OK = isset($_POST['shipping']) ? true : false;
        if ($OK && isset($missing) && $_POST['shipping'] == 'USPS Priority Mail') { ?>
        checked="checked"
        <?php } ?>
        />
        <label for="UPS" class="style7">USPS Priority Mail $4.95</label>
        <br />
        <input name="shipping" type="radio" value="FedEx" id="FedEx"
        <?php
        if ($OK && isset($missing) && $_POST['shipping'] == 'FedEx Overnight') { ?>
        checked="checked"
        <?php } ?>
        />
        <label for="FedEx" class="style7">FedEx Overnight Shipping $35.00</label>
        </fieldset> </td>
  </tr>
  
  <tr>
    <td height="31" colspan="3" bgcolor="#CECECE"> </td>
  </tr>
  <tr>
    <td height="31" colspan="3" bgcolor="#F5F5F5"><div align="center" class="style6">Billing Information</div></td>
    </tr>
  <tr>
    <td height="31" colspan="3" bgcolor="#CECECE"> </td>
  </tr>
  <tr>
    <td width="155" height="10" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><span class="style1">First Name:</span>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input id="billingfirstname" name="billingfirstname" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingfirstname']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('billingfirstname', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your first name</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Last Name:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input id="billinglastname" name="billinglastname" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billinglastname']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('billinglastname', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your last name</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td height="31" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Card Type :</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <p> <div align="left" class="clearIt"></label>
    <?php
        if (isset($missing) && in_array('cardtype', $missing)) { ?>
            <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your credit card type</div>
      </div>
      <div align="left">
        <?php } ?>
      </div>
          <select name="cardtype" id="cardtype">
            <option value="" 
          <?php
          if (!$_POST || $_POST['cardtype'] == '0') {
            echo 'selected="selected"';
            } ?>
          >-- Select one --</option>
            <option value="amex"
          <?php
          if (isset($missing) && $_POST['cardtype'] == 'amex') {
            echo 'selected="selected"';
            } ?>
          >AMEX</option>
            <option value="discover"
          <?php
          if (isset($missing) && $_POST['cardtype'] == 'discover') {
            echo 'selected="selected"';
            } ?>
          >Discover</option>
            <option value="mastercard"
          <?php
          if (isset($missing) && $_POST['cardtype'] == 'mastercard') {
            echo 'selected="selected"';
            } ?>
          >Mastercard</option>
            <option value="visa"
          <?php
          if (isset($missing) && $_POST['cardtype'] == 'visa') {
            echo 'selected="selected"';
            } ?>
          >Visa</option>
            <?php
    if (isset($missing) && in_array('cardtype', $missing)) { ?>
            <span class="warning"> </span></div>
            <div style= "color:red; font-size: 11px;">
            <div align="left">Please enter your card type</div>
            </div>
            <div align="left">
            <?php } ?>
            </div>
            </span>
          </select>
          </p></td>
  </tr>
  <tr>
    <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Credit Card Number :</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input id="creditcardnumber" name="creditcardnumber" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['creditcardnumber']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('creditcardnumber', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your credit card number</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Exp.</strong></div></td>
    <td width="100" bgcolor="#F5F5F5">
    <div align="left">
  <span class="style1">Month:</span>
 
  <select name="expmonth" id="expmonth">
    <option value=""
    <?php 
    if (!$_POST || $_POST['expmonth'] == '') { 
    echo 'selected="selected"';
    } ?>
     >--</option>
        <option value="01"
<?php if (isset($missing) && $_POST['expmonth'] == '01') { 
        echo 'selected="selected"';
        }?>
>01</option>
        <option value="02"
<?php if (isset($missing) && $_POST['expmonth'] == '02') { ?>
<?php } ?>
>02</option>
        <option value="03"
<?php if (isset($missing) && $_POST['expmonth'] == '03') { ?>
<?php } ?>
>03</option>
        <option value="04"<?php if (isset($missing) && $_POST['expmonth'] == '04') { ?>
<?php } ?>
>04</option>
        <option value="05"<?php if (isset($missing) && $_POST['expmonth'] == '05') { ?>
<?php } ?>
>05</option>
        <option value="06"<?php if (isset($missing) && $_POST['expmonth'] == '06') { ?>
<?php } ?>
>06</option>
        <option value="07"<?php if (isset($missing) && $_POST['expmonth'] == '07') { ?>
<?php } ?>
>07</option>
        <option value="08"<?php if (isset($missing) && $_POST['expmonth'] == '08') { ?>
<?php } ?>
>08</option>
        <option value="09"<?php if (isset($missing) && $_POST['expmonth'] == '09') { ?>
<?php } ?>
>09</option>
        <option value="10"<?php if (isset($missing) && $_POST['expmonth'] == '10') { ?>
<?php } ?>
>10</option>
        <option value="11"<?php if (isset($missing) && $_POST['expmonth'] == '11') { ?>
<?php } ?>
>11</option>
        <option value="12"<?php if (isset($missing) && $_POST['expmonth'] == '12') { ?>
<?php } ?>
>12</option>
<?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['expmonth']).'"';
    } ?>
  </select>
  </label>
      
  <?php
    if (isset($missing) && in_array('expmonth', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your expiration month</div>
      </div>
      <div align="left">
        <?php } ?>
    </div></td>
    <td width="40" bgcolor="#F5F5F5">
    <div align="left">
  <span class="style1">Year:</span>
  <select name="expyear" id="expyear">
    <option value=""
    <?php 
    if (!$_POST || $_POST['expyear'] == '') { ?>
    selected="selected"
    <?php } ?>
     >Year</option>
        <option value="2008"<?php if (isset($missing) && $_POST['expyear'] == '2008') { ?>
<?php } ?>
>2008</option>
        <option value="2009"<?php if (isset($missing) && $_POST['expyear'] == '2009') { ?>
<?php } ?>
>2009</option>
        <option value="2010"<?php if (isset($missing) && $_POST['expyear'] == '2010') { ?>
<?php } ?>
>2010</option>
        <option value="2011"<?php if (isset($missing) && $_POST['expyear'] == '2011') { ?>
<?php } ?>
>2011</option>
        <option value="2012"<?php if (isset($missing) && $_POST['expyear'] == '2012') { ?>
<?php } ?>
>2012</option>
        <option value="2013"<?php if (isset($missing) && $_POST['expyear'] == '2013') { ?>
<?php } ?>
>2013</option>
        <option value="2014"<?php if (isset($missing) && $_POST['expyear'] == '2014') { ?>
<?php } ?>
>2014</option>
        <option value="2015"<?php if (isset($missing) && $_POST['expyear'] == '2015') { ?>
<?php } ?>
>2015</option>
        <option value="2016"<?php if (isset($missing) && $_POST['expyear'] == '2016') { ?>
<?php } ?>
>2016</option>
        <option value="2017"<?php if (isset($missing) && $_POST['expyear'] == '2017') { ?>
<?php } ?>
>2017</option>
        <option value="2018"<?php if (isset($missing) && $_POST['expyear'] == '2018') { ?>
<?php } ?>
>2018</option>
        <option value="2019"<?php if (isset($missing) && $_POST['expyear'] == '2019') { ?>
<?php } ?>
>2019</option>
        <option value="2020"<?php if (isset($missing) && $_POST['expyear'] == '2020') { ?>
<?php } ?>
>2020</option>
  </select>
      
  <?php
    if (isset($missing) && in_array('expyear', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your expiration year</div>
      </div>
      <div align="left">
        <?php } ?>
    </div></td>
  </tr>
  <tr>
    <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">CVV #:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input name="cvv" type="text" class="textbox" id="cvv" size="4" maxlength="4" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['cvv']).'"';
    } ?> />
      What's this?<?php 
    if (isset($missing) && in_array('cvv', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your credit card verification number</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Address:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input name="billingaddress1" type="text" class="formbox" id="billingaddress1" maxlength="35" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingaddress1']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('billingaddress1', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your billing address</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><strong class="style1">Address:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input name="billingaddress2" type="text" class="formbox" id="billingaddress2" maxlength="35" 
      <?php if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingaddress2']).'"';
    } ?>
    /> 
    </div>
    </td>
  </tr>
  <tr>
    <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">City :</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input id="billingcity" name="billingcity" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingcity']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('billingcity', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your billing city </div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">State/Province:</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
  <input id="billingstate" name="billingstate" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingstate']).'"';
    } ?> />
      
  <?php
    if (isset($missing) && in_array('billingstate', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your billing state/province </div>
      </div>
      <div align="left">
        <?php } ?>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Postal Code :</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
  <input name="billingpostalcode" type="text" class="textbox" id="billingpostalcode" size="15" maxlength="20" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingpostalcode']).'"';
    } ?> />
      
  <?php
    if (isset($missing) && in_array('billingpostalcode', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your billing postal code </div>
      </div>
      <div align="left">
        <?php } ?>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Email:</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input name="email" type="text" size="40" maxlength="60" <?php if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['email']).'"';
    } ?>/>
      
      <?php
    if (isset($missing) && in_array('email', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;" >
        <div align="left">Please enter your email address</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><strong class="style1">Phone Number:</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <input name="billingphonenumber" type="text" size="15" maxlength="20" <?php if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingphonenumber']).'"';
    } ?>/>
      
      <?php
    if (isset($missing) && in_array('billingphonenumber', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your phone number</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#CECECE"> </td>
  </tr>
  <tr>
  
  
    <td colspan="3" bgcolor="#F5F5F5"><div align="center" class="style5"><em>Shipping Information </em></div></td>
    </tr>
  <tr>
    <td colspan="3" bgcolor="#CECECE"> </td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><span class="style1">First Name:</span>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
      <input id="shippingfirstname" name="shippingfirstname" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippingfirstname']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('shippingfirstname', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your first name</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Last Name:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
      <input id="shippinglastname" name="shippinglastname" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippinglastname']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('shippinglastname', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your last name</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Address:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
      <input name="shippingaddress1" type="text" class="formbox" id="shippingaddress1" maxlength="35" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippingaddress1']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('shippingaddress1', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your shipping address</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><strong class="style1">Address:</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
      <input name="shippingaddress2" type="text" class="formbox" id="shippingaddress2" maxlength="35" 
      /> </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">City :</strong>
    </div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
      <input id="shippingcity" name="shippingcity" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippingcity']).'"';
    } ?> />
      <?php
    if (isset($missing) && in_array('shippingcity', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your shipping city </div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">State/Province:</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
  <input id="shippingstate" name="shippingstate" type="text" class="formbox" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippingstate']).'"';
    } ?> />
      
  <?php
    if (isset($missing) && in_array('shippingstate', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your shipping state/province </div>
      </div>
      <div align="left">
        <?php } ?>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><font size="2" color="red">*</font><strong class="style1">Postal Code :</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
  <input name="shippingpostalcode" type="text" class="textbox" id="shippingpostalcode" size="15" maxlength="20" 
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippingpostalcode']).'"';
    } ?> />
      
  <?php
    if (isset($missing) && in_array('shippingpostalcode', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your shipping postal code </div>
      </div>
      <div align="left">
        <?php } ?>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><strong class="style1">Phone Number:</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5"><div align="left">
      <input name="shippingphonenumber" type="text" size="15" maxlength="20" <?php if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['shippingphonenumber']).'"';
    } ?>/>
      
      <?php
    if (isset($missing) && in_array('shippingphonenumber', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your phone number</div>
      </div>
      <div align="left">
        <?php } ?>
      </div></td>
  </tr>
  <tr>
    <td bgcolor="#F5F5F5"><div align="right"><strong class="style1">Comments:</strong></div></td>
    <td colspan="2" bgcolor="#F5F5F5">
    <div align="left">
      <textarea name="comments" cols="30" rows="5"><?php
    if (isset($missing)) {
    echo htmlentities($_POST['comments']);
    } ?></textarea>
      
      <?php
    if (isset($missing) && in_array('comments', $missing)) { ?>
        <span class="warning">      </div>
      <div style= "color:red; font-size: 11px;">
        <div align="left">Please enter your comments</div>
      </div>
      <div align="left">
        <?php } ?>  
      </div></td>
  </tr>
  
  
  <tr>
    <td colspan="3">
    <div align="center"> 
    <input name="send" id="send" type="submit" value="Submit My Order" />
</div></td>
    </tr>
</table>
</form>
    <?php include('includes/footer.inc.php'); ?>
</div>
</body>
</html>

Re: Issues with emailing a form

Posted: Thu Apr 03, 2008 7:14 pm
by ggrant3
<crickets>

Anybody??

</crickets>

Re: Issues with emailing a form

Posted: Fri Apr 04, 2008 12:59 am
by Christopher
That is lot of code to expect people to wade through. If you could focus on the code where you check whether fields have been filled in -- it would make it easier for people to provide help.

Re: Issues with emailing a form

Posted: Fri Apr 04, 2008 9:13 am
by ggrant3
arborint wrote:That is lot of code to expect people to wade through. If you could focus on the code where you check whether fields have been filled in -- it would make it easier for people to provide help.
Thats what I was worried about. I just wanted you guys to be able to see how everything was laid out.

Okay here is one portion of what I am having trouble with.

Code: Select all

<input name="billingaddress1" type="text" class="formbox" id="billingaddress1" maxlength="35"
    <?php
    if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingaddress1']).'"';
    } ?> />
    <?php
    if (isset($missing) && in_array('billingaddress1', $missing)) { ?>
        <span class="warning">      </div>
     <div style= "color:red; font-size: 11px;">
         <div align="left">Please enter your billing address</div>
       </div>
       <div align="left">
         <?php } ?>
       </div>
</td>
   </tr>
   <tr>
     <td width="155" height="31" bgcolor="#F5F5F5"><div align="right"><strong class="style1">Address:</strong>
     </div></td>
     <td colspan="2" bgcolor="#F5F5F5">
     <div align="left">
       <input name="billingaddress2" type="text" class="formbox" id="billingaddress2" maxlength="35"
      <?php 
         if (isset($missing)) {
    echo 'value="'.htmlentities($_POST['billingaddress2']).'"';
      } ?>
     />
The code above is for the two address form fields (billingaddress1 and billingaddress2) that I have listed for my order form.

How I have it setup is that all of the information in the form fields will be emailed to me whether the non-required fields have any text in them or not. But if I test the form and I put information inside one of the non-required fields it does not email that information to me.

Example,
On my form I have two separate text boxes for the address portion of the form, I have them listed as billingaddress1 and billingaddress2. Basically, the first address field (billingaddress1) is required, but the second address field (billingaddress2) would be optional just in case someone has any additional address information (like a bldg or suite #). But since not everyone would need the billingaddress2 field I don't have it as a required field.

But when I test the form I fill out every field including the billingaddress2 field, I put in a suite number (suite 118). But when the email arrives it has the information from billingaddress1 but billingaddress2 doesn't bring any information, it is always blank, even though I put the "suite 118" into the form when it was filled out. What comes in the email is "Billing Address 2: " instead of "Billing Address 2: Suite 118". See what I mean?