I have set up an online order form and have the form output emailed to my wife's inbox. However, currently all values come out in a list format that is hard for her to follow.
The following is an order from our Web Order Form:
Name: Address: Phone: Email: Book Number: Page Number1: Product Number1: Product1: QTY1: Unit Price1: Total Price1: Page Number2: Product Number2: Product2: QTY2: Unit Price2: Total Price2: Page Number3: Product Number3: Product3: QTY3: Unit Price3: Total Price3:
I want to format the email to look similar to the input form on the website. I have been trying to reverse engineer other people's examples with no luck. I would include snapshot of the form but my reputation isn't high enough. Essentially it is a table containing form fields corresponding to the data I need to collect (think order form). Below is a sample of the PHP code it is submitted to.
<?php
$from = $_REQUEST['Email'] ;
$to = "myemailaddress@gmail.com";
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Online Order Submission";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Address"} = "Address";
$fields{"Phone"} = "Phone";
$fields{"Email"} = "Email";
$fields{"Item1Page"} = "Page Number1";
$fields{"Number1"} = "Product Number1";
$fields{"Product1"} = "Product1";
$fields{"QTY1"} = "QTY1";
$fields{"Uprice1"} = "Unit Price1";
$fields{"Tprice1"} = "Total Price1";
$fields{"Item2Page"} = "Page Number2";
$fields{"Number2"} = "Product Number2";
$fields{"Product2"} = "Product2";
$fields{"QTY2"} = "QTY2";
$fields{"Uprice2"} = "Unit Price2";
$fields{"Tprice2"} = "Total Price2";
// Variables removed for clarity
$fields{"Item11Page"} = "Page Number11";
$fields{"Number11"} = "Product Number11";
$fields{"Product11"} = "Product11";
$fields{"QTY11"} = "QTY11";
$fields{"Uprice11"} = "Unit Price11";
$fields{"Tprice11"} = "Total Price11";
$body = "The following is an order from our Web Order Form:\n\n"; foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: myemailaddress@gmail.com";
$subject2 = "Thank you for your order";
$autoreply = "Thank you for your order. We will contact you when your order is ready for delivery.";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.website.com/thankyou.html" );}
else
{print "We encountered an error sending your mail, please try again later."; }
}
}
?>
Any help would be appreciated
UPDATE
I have tried a number of the below mentioned references and ammendments. The current edit looks like this:
<?php
$from = $_REQUEST['Email'] ;
$to = "myemailaddress@live.com";
$Name = $_REQUEST['Name'] ;
$headers = "From: $from";
$headers .= "Content-type: text/html\r\n";
$subject = "Order Submission TEST";
$message = "<html><body><br><br>The following is an order from our TEST Order Form<br><br><br>";
$message .= "<table>";
$message .= "<tr><td>Name: </td><td>" . strip_tags($_POST['Name']) . "</td></tr>";
$message .= "<tr><td>Address: </td><td>" . strip_tags($_POST['Address']) . "</td></tr>";
$message .= "<tr><td>Phone No: </td><td>" . strip_tags($_POST['Phone']) . "</td></tr>";
$message .= "<tr><td>E-mail: </td><td>" . strip_tags($_POST['Email']) . "</td></tr>";
$message .= "</table>";
$message .= "<table border=1><tr><td>Page No.</td><td>Product No.</td><td>Product Name</td><td>QTY</td><td>Unit Price</td><td>Total Price</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item1Page']) . "</td><td>" . strip_tags($_POST['Number1']) . "</td><td>" . strip_tags($_POST['Product1']) . "</td><td>" . strip_tags($_POST['QTY1']) . "</td><td>" . strip_tags($_POST['Uprice1']) . "</td><td>" . strip_tags($_POST['Tprice1']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item2Page']) . "</td><td>" . strip_tags($_POST['Number2']) . "</td><td>" . strip_tags($_POST['Product2']) . "</td><td>" . strip_tags($_POST['QTY2']) . "</td><td>" . strip_tags($_POST['Uprice2']) . "</td><td>" . strip_tags($_POST['Tprice2']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item3Page']) . "</td><td>" . strip_tags($_POST['Number3']) . "</td><td>" . strip_tags($_POST['Product3']) . "</td><td>" . strip_tags($_POST['QTY3']) . "</td><td>" . strip_tags($_POST['Uprice3']) . "</td><td>" . strip_tags($_POST['Tprice3']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item4Page']) . "</td><td>" . strip_tags($_POST['Number4']) . "</td><td>" . strip_tags($_POST['Product4']) . "</td><td>" . strip_tags($_POST['QTY4']) . "</td><td>" . strip_tags($_POST['Uprice4']) . "</td><td>" . strip_tags($_POST['Tprice4']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item5Page']) . "</td><td>" . strip_tags($_POST['Number5']) . "</td><td>" . strip_tags($_POST['Product5']) . "</td><td>" . strip_tags($_POST['QTY5']) . "</td><td>" . strip_tags($_POST['Uprice5']) . "</td><td>" . strip_tags($_POST['Tprice5']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item6Page']) . "</td><td>" . strip_tags($_POST['Number6']) . "</td><td>" . strip_tags($_POST['Product6']) . "</td><td>" . strip_tags($_POST['QTY6']) . "</td><td>" . strip_tags($_POST['Uprice6']) . "</td><td>" . strip_tags($_POST['Tprice6']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item7Page']) . "</td><td>" . strip_tags($_POST['Number7']) . "</td><td>" . strip_tags($_POST['Product7']) . "</td><td>" . strip_tags($_POST['QTY7']) . "</td><td>" . strip_tags($_POST['Uprice7']) . "</td><td>" . strip_tags($_POST['Tprice7']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item8Page']) . "</td><td>" . strip_tags($_POST['Number8']) . "</td><td>" . strip_tags($_POST['Product8']) . "</td><td>" . strip_tags($_POST['QTY8']) . "</td><td>" . strip_tags($_POST['Uprice8']) . "</td><td>" . strip_tags($_POST['Tprice8']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item9Page']) . "</td><td>" . strip_tags($_POST['Number9']) . "</td><td>" . strip_tags($_POST['Product9']) . "</td><td>" . strip_tags($_POST['QTY9']) . "</td><td>" . strip_tags($_POST['Uprice9']) . "</td><td>" . strip_tags($_POST['Tprice9']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item10Page']) . "</td><td>" . strip_tags($_POST['Number10']) . "</td><td>" . strip_tags($_POST['Product10']) . "</td><td>" . strip_tags($_POST['QTY10']) . "</td><td>" . strip_tags($_POST['Uprice10']) . "</td><td>" . strip_tags($_POST['Tprice10']) . "</td></tr>";
$message .= "<tr><td>" . strip_tags($_POST['Item11Page']) . "</td><td>" . strip_tags($_POST['Number11']) . "</td><td>" . strip_tags($_POST['Product11']) . "</td><td>" . strip_tags($_POST['QTY11']) . "</td><td>" . strip_tags($_POST['Uprice11']) . "</td><td>" . strip_tags($_POST['Tprice11']) . "</td></tr>";
$message .= "<tr><td colspan=5 align=right>Order Processing Charge </td><td align=right>$2.50</td></tr>";
$message .= "<tr><td colspan=5 align=right>Order TOTAL </td><td align=right></td></tr>";
$message .= "</table></body></html>";
$headers2 = "From: myemailaddress@live.com ";
$subject2 = "Thank you for your order ";
$autoreply = "Thank you for your order. We will contact you when your order is ready for delivery. ";
$send = mail($to,$subject,$message,$headers);
$send2 = mail($from,$subject2,$autoreply,$headers2);
if($send)
{header( "Location: thankyou.html" );}
else
{print "We encountered an error sending your mail, please try again later."; }
?>
I have borrowed a number of ideas and this incarnation has removed the array in favour of directly injecting the variables into the table. The $send2 line works fine since the "Thank you for your order" email is received and the redirect to thankyou.html works also. However, the email with the order is not received.