Order Form Part 10: The PHP Script - Confirmations
Here's the code we need:
if( !empty($_POST["qtyA"]) )
$qtyA = $_POST["qtyA"];
$totalA = $qtyA * 1.25;
$qtyA = 0;
$totalA = 0;
$qtyB = $_POST["qtyB"];
$totalB = $qtyB * 2.35;
$qtyB = 0;
$totalB = 0;
$qtyC = $_POST["qtyC"];
$totalC = $qtyC * 3.45;
$qtyC = 0;
$totalC = 0;
Nothing too complicated about that!
OK! Now that we have all our data elements we can send out our confirmation email, and another to our own "Order Processing Department" to let them (our self, perhaps?!!) know that an order has been entered. One thing to remember when sending out these confirmation emails, though it doesn't apply to our present example, is that it is unwise (or worse) to include any credit card information in an email. It's always worth paying attention to the kind of information you do send via email -- sensitive information is just that, sensitive.
So, to the emails:
$mailto = "firstname.lastname@example.org";
$subject = "Web Order";
$body .= "\n\n";
$body .= "Name: " . $Name . "\n";
$body .= "Email: " . $Email . "\n";
$body .= "Other Contact Info: " . $OtherInfo . "\n";
$body .= "\n\n";
$body .= "Class A Widgets: (" . $qtyA . " * 1.25) = " . $totalA . "\n";
$body .= "Class B Widgets: (" . $qtyB . " * 2.35) = " . $totalB . "\n";
$body .= "Class C Widgets: (" . $qtyC . " * 3.45) = " . $totalC . "\n";
$body .= "\n";
$body .= "TOTALS: " . $GrandTotal . "\n";
mail($Email, $subject, $body);
Note that when building the body of the email, the first line uses the assignment operator = while the remaining use the concatenate assignment operator .= I thought it worth a mention because it's easy to miss the period.
If you wanted to have a different lead line for your order department than for the customer's confirmation email, you could build a second body and send that one to your order desk. PHP makes life very easy, all things considered! There are, of course, lots of other ways you could accomplish this, but, we only really need one, don't we?!!
We can also use the body of our email to return a confirmation page to the browser of our site visitor / customer, like this:
echo "The following information was sent.";
PHP is so elegant, don't you think? We're almost done with processing our form
IT Solutions Builder TOP IT RESOURCES TO MOVE YOUR BUSINESS FORWARD
Which topic are you interested in?
What is your company size?
What is your job title?
What is your job function?
Searching our resource database to find your matches...