Jump to content

sending formatted emails


awesomejoe

Recommended Posts

Hi, I'm a noob at php so please bear with me. I'm trying to make an order form for my website and have the information sent to my email, but it is not completely working. This is my code:

<html><body>
<?php

$order = $_POST['order'];
$quantity = $_POST['quantity'];
$price = $_POST['price'];
$donation = $_POST['Donation'];
$totalprice = 0;
[color=red]
echo "You ordered: " . "
";
for ($i = 0; $i < sizeof($order); $i++) {
   $price[$i] = $price[$i] * $quantity[$i];
   echo $quantity[$i] . " ". $order[$i] . " : $" . $price[$i] . "
";
   $totalprice = $totalprice + $price[$i];
} 
$totalprice = $totalprice + $donation;
echo "
Your donation: $" . $donation . "
";
echo "Your subtotal: $" . $totalprice . "

";
echo "This information has been sent to your email address.
";
echo "Thank you for ordering!"; [/color]

$to = "--@---" ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$headers = "From: $from"; 
$subject = $_REQUEST['Subject'] ; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Email"} = "Email"; 
$fields{"Subject"} = "Subject";
$fields{"order"} = "Order";
$fields{"quantity"} = "Quantity";
$fields{"Donation"} = "Donation";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

if($from == '') {
echo "<script language=\"JavaScript\">\n"; 
echo "alert('You have not entered an email, please go back and try again');\n"; 
echo "</script>"; 
}


else { 
$send = mail($to, $subject, $body, $headers); 
if($send) 
{
}

{print "We encountered an error sending your mail, please notify ---@----"; } 
}

?> 

</body></html>

 

 

The problem is that when I receive the email, the Order and Quantity fields just say "Array" instead of their actual values. I would like to send an email formatted the same way as the text I printed out (red text) so is this possible and if so, how can I do this? Any help would be greatly appreciated 

 

 

Link to comment
Share on other sites

Hello Joe,

  Please use

 

[code=php:0]... 

[/code]

 

Around your code snippets.  It's easier to read that way.  I editted your post to do this, which is something I won't do in the future, but seeing as this is your first post.  ;)

 

I also took out your email addy's, don't think you want to include those, or specific urls or passwords in the future.  This site is indexed heavily by google.

Link to comment
Share on other sites

It's because you're trying to use the php block operator "{}" rather than the array operator "[]". Hence your array remains undefined.

Try this as your array definition:

 

$fields['Name'] = "Name"; 
$fields['Email'] = "Email"; 
$fields['Subject'] = "Subject";
$fields['order'] = "Order";
$fields['quantity'] = "Quantity";
$fields['Donation'] = "Donation";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.