How do I create a PHP order form that emails the sender what is sent?

matt2654 used Ask the Experts™
I need to create an order form that the persons who order materials get a response that 1. the order was sent, and 2. a copy of the order. This is the script I have so far:

//Linecraft PHP Form mail v.1.0.0
      $subject="Book Order Form";
      $message_header="<b>Book Order Form</b><br>\r\n<hl><br>\r\n";
      $message_body="A Selector has sent the following order:<br><br>";
      $format_html= "\r\nContent-type: text/plain; charset=utf-8";
      //If HTML
            $format_html= "\r\nContent-type: text/html; charset=utf-8";
      foreach($_POST as $fieldName => $value){
            if(!in_array($fieldName,$exception_fields) && ($value!="" || $skip_blank=="")){
                  $fieldName=str_replace("_"," ",$fieldName);
                  $message_body=$message_body.$o_t.$fieldName.$c_t.": ".$value.$br;
      $headers.=($cc!="")?("\r\nCc: " . $cc):"";
      $headers.=($bcc!="")?("\r\nBcc: " . $bcc):"";
      if(mail($to, stripslashes($subject), stripslashes($message),$headers)){
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en" lang="en">
<link href="/style.css" rel="stylesheet" type="text/css" />
<title>Book Selection</title>
<script type="text/javascript">
function addRowToTable()
  var tbl = document.getElementById('tbl1300');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  //  var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);"dynaRows"; = "row_"+iteration;
  //  cell 0
  var cell1 = row.insertCell(0);
  var el = document.createElement('input');
  el.type = 'text'; = 'title' + iteration; = 'title' + iteration;
  el.size = 20;

  //cell 1
  var cell1 = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'text'; = 'author' + iteration; = 'author' + iteration;
  el.size = 20;

//cell 2
  var cell2 = row.insertCell(2);
  var el = document.createElement('input');
  el.type = 'text'; = 'isbn' + iteration; = 'isbn' + iteration;
  el.size = 20;
   //cell 3
  var cell3 = row.insertCell(3);
  var el = document.createElement('input');
  el.type = 'text'; = 'vendor' + iteration; = 'vendor' + iteration;
  el.size = 20;
  // delete button
  var cell3 = row.insertCell(4);
  var el = document.createElement('input');
  el.type = 'button';
  el.value = 'Remove'; = 'removeBtn' + iteration; = 'removeBtn' + iteration;
  el.size = 20;
// function to delete the row
function deleteRow(rowId)
      var rowObj = document.getElementById(rowId);
//function to attch event
function addEvents(element,type,handler,capture)
         if (document.addEventListener)
                     element.addEventListener(type, handler, capture);
         else if (document.attachEvent)
                     element.attachEvent("on" + type, handler);
<form name="h" method="post">
<input type="hidden" name="Sort-order" value="title, author, ISBN, vendor"/>
<label for="Order-submitted-by">Selector</label>
<input type="text" name="Order-submitted-by" id="Order-submitted-by" />
<label for="email"><strong>Email</strong></label>
<input type="text" name="email" id="email" />
<table id="tbl1300">
    <td class="txtBase"><strong>Title</strong></td>
    <td class="txtBase"><strong>Author</strong></td>
    <td class="txtBase"><strong>ISBN</strong></td>
    <td class="txtBase"><strong>Vendor</strong></td>
    <tr id="row_1" name="dynaRows">
        <td><input name="title" type="text" size="20" maxlength="25"></td>
        <td><input name="author" type="text" size="20" maxlength="25"></td>
        <td><input name="ISBN" type="text" size="20" maxlength="10"></td>
        <td><input name="vendor" type="text" size="20" maxlength="10"></td>
  <input type="button" name="Add" value="Add another item row" onClick="javascript: return addRowToTable();">
  <input type="submit" name="Submit" value="Send order">
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®



# To Email Address
$emailaddress="user <>";

# From Email Address
$fromaddress = "user <>";

# Message Subject
$emailsubject="Re: great news";

  $headers .= 'From: '.$fromaddress.''.$eol;
  $headers .= 'Reply-To: '.$fromaddress.''.$eol;
  $headers .= 'Return-Path: '.$fromaddress.''.$eol;    // t

$msg = "something to read";  

mail($emailaddress, $emailsubject, $msg, $headers);

if you want to send the same thing to 2 emails then use this.

mail(",".$_POST['email'],$emailsubject, $msg, $headers);
Hello, I recommend you use PhpMailer for this.


Hi eNarc, Thanks for posting your solution. Could you go one step more and tell me if I need to replace parts of my code with your new parts, or do I append the php code? If I append, which that is what I *think* I should do because of the *$eol="\r\n";* then wher do I do this?
Thank you for your lightning response! I really do appreciate it.
your very welcome.

the $eol="\r\n"; is needed at the end of each tag.

though from what I see in your code, you've already got the \r\n

 $headers.=($cc!="")?("\r\nCc: " . $cc):"";
      $headers.=($bcc!="")?("\r\nBcc: " . $bcc):"";

$eol="\r\n"; is only there in a string as a easier way to update if need be.

for example there at the front like this.

$format_html= "\r\nContent-type: text/html; charset=utf-8";

and the $eol just is there to make it neater. and puts it at the end like so.

$format_html= "Content-type: text/html; charset=utf-8".$eol;

from looking at your code $to="m?????ell@f??.???"; could be added like "Name <>,Name <>"; or like "Your Name <>,There Name <".$_POST['email'].">";

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial