email order form not working right?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

email order form not working right?

Post by darkfreaks »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


well i sort of want it to verify the email then add up the quantity fields then mail the total amount and price to admin@yoursite.com (example adress).

i want it to read $name has purchased $totalqty items totaling $totalqty in the message and for the subject "my order".

i want a from field to that displays the email field. so you know what email its from.

and after its submitted i want it to echo $name you have bought $totalqty totaling $totalamount , thanks for shopping here!"

the code so far is

Code: Select all

<?php
 

$NNSQTY = $_POST['NNSQTY'];
$CBFNQTY = $_POST['$CBFNQTY'];
$AKNQTY = $_POST['$AKNQTY'];
$CFNQTY = $_POST['$CFNQTY'];
$CVNQTY = $_POST['$CVNQTY'];
$from = $_POST['name'];
$email = $_POST['email'];

define("NECKLACEOFTHENIGHTSKY", 50);
define("CHAINAILEFANCYBEADEDNECKLACE", 50);
define("ANTIQUEKEYNECKLACE", 30);
define("CHAINMAILEFANCYNECKLACE", 50);
define("CHAINMAILEVNECKLACE", 50);



$totalqty = $NNSQTY+$CBFNQTY+$AKNQTY+$CFNQTY+$CVNQTY ;

$totalamount = $NNSQTY * NECKLACEOFTHENIGHTSKY
               +$CBFNQTY * CHAINAILEFANCYBEADEDNECKLACE
			   +$AKNQTY * ANTIQUEKEYNECKLACE
               +$CFNQTY *CHAINMAILEFANCYNECKLACE
               +$CVNQTY* CHAINMAILEVNECKLACE;

$totalqty = 0;
$totalamount= 0.00;
//mail

$to      = "admin@tattoos-n-piercings.com ";
$subject = "SubjectMy Order";
$email = $_POST['email'];
$from =  ($_POST['name']);
$msg = "Message from: $from Has Bought $totalqty Items totaling $totalamount .";

if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $_POST['email'])) 
{ 
echo 'Please enter a valid email address.';

} else {

$send= mail("$to", "$email", "$subject","$from","$msg"); 
}

if($send)
{
echo "Your order has been sent successfully!  Lily Will Contact you shortly. You have bought $totalqty items totaling $totalamount";

} else {
echo "There was an error sending the order, please go back and try again.";
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You haven't told use what the problem is, you've only told use what you want to do ;)

FYI... It's not good practise to define constants for things like prices. Constants are more for things which are set in stone, unlike prices.

Also, your maths is flawed. You need parentheses around each of the $qty * $price lines so that it adds up the resulting numbers.

$to has a space after it. Why?

Read the manual page for mail(). You have the parameters in the wrong order ;)
Post Reply