Format email like a form
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
No comments:
Post a Comment