I got it to work, sort of 😃
Here's my code:
<?php
$page_title = 'Simple Calculator';
if (isset($_POST['calculated'])) {
if ( is_numeric($_POST['quantity'])
&& is_numeric($_POST['price']) &&
is_numeric($_POST['tax']) ) {
$taxrate = $_POST['tax'] / 100;
$total = ($_POST['quantity'] * $_POST['price']) * ($taxrate + 1);
echo '<h1>Total Cost</h1>
<p>The total cost of purchasing ' . $_POST['quantity'] . ' customer service options at $' . number_format ($_POST ['price'], 2) . ' each, including a tax rate of ' . $_POST['tax'] . '%, is $' . number_format ($total, 2) . '.</p><p><br /></p>';
} else {
echo '<h1>Error!</h1>
<p>Please enter a valid quantity, price, and tax.</p><p><br /></p>';
}
}
?>
<h2>Simple Calculator</h2>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Quantity: <input type="text" name="quantity" size="5" maxlength="10" /></p>
<p>Price: <input type="text" name="price" size="5" maxlength="10" /></p>
<p>Tax (%): <input type="text" name="tax" size="5" maxlength="10" /></p>
<p><input type="submit" name="calculated" value="Calculate!"/></p>
<br>
</form>
<h1>Customer Feedback</h1>
<p>Please tell us what you think.</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Your name: <br />
<input type=text name="name" size=40><br />
Your email address: <br />
<input type=text name="email" size=40><br />
Your feedback:<br />
<textarea name="feedback" rows=5 cols=30>
</textarea>
<br />
<input type=submit name="mailit" value="MAIL IT">
</form>
<?php
//mail it
if(isset($_POST['mailit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$toaddress = 'me@t.net';
$subject = 'Feedback from web site';
$mailcontent = "Customer order! \n".
"Quantity: \n".$_POST['quantity']."\n".
"Price: \n".$_POST['price']."\n".
"Tax: \n".$_POST['tax']."\n".
"Total: \n".$total."\n";
$fromaddress = 'From: webserver@example.com';
mail($toaddress, $subject, $mailcontent, $fromaddress);
}
?>
</form>
Here's what works. Customers can fill in values and get price calculations. When they get the price level they want, they send it to me via email. I get the messages with no problem.
Here's what doesn't work:
When they get their orders done and mail it, the values do not show up in the email message. Plus, a blank message always follows after someone submits mail. I tried to put a check, so that if "$POST['mailit'] isn't set, no message comes. That didn't work.
The funny thing is that when I get rid of the if(isset($POST['mailit'] line, the values that are calculated DO show up in the email, but I get a blank one that follows the email without order amounts. Plus, when someone wants to calculate their order but not send me a message, I get a blank.
Can SOMEONE please help me?
Thanks