Page is a not externally linkable
LinusIT - 9:50 pm on Mar 3, 2011 (gmt 0)
I've had help with this before and had excellent results. I decided to add more information to the email but can't get it reading the data. It all works fine apart from the grabbing the delivery address. I have tried what I know but to no avail.
Here's the code:
<?php
$orderid = Trim(stripslashes($_POST['ordernumber']));
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'psw';
$dbname = 'store';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn) {
die('Failed to connect to server: ' . mysql_error());
}
mysql_select_db($dbname);
$sql="SELECT * FROM orders_products WHERE orders_id = '".$orderid."'";
$result = mysql_query($sql);
$firstname = Trim(stripslashes($_POST['firstname']));
$lastname = Trim(stripslashes($_POST['lastname']));
$email = Trim(stripslashes($_POST['email']));
$mtcn = Trim(stripslashes($_POST['mtcn']));
$amount = Trim(stripslashes($_POST['amount']));
$country = Trim(stripslashes($_POST['country']));
$ordernumber = Trim(stripslashes($_POST['ordernumber']));
$currency = Trim(stripslashes($_POST['currency']));
$emailto = "to@email.com";
$emailcc = "cc@email.com";
$subject = "Information - Order No:";
$headers = "From: $email" . "\r\n" . "CC: $emailcc";
// prepare email body text
$body .= "--------------------------------------\n";
$body .= "Details\n";
$body .= "--------------------------------------\n";
$body .= "First name: ";
$body .= $firstname;
$body .= "\n";
$body .= "Last name: ";
$body .= $lastname;
$body .= "\n";
$body .= "Email Address: ";
$body .= $email;
$body .= "\n\n";
$body .= "--------------------------------------\n";
$body .= "Products\n";
$body .= "--------------------------------------\n";
while($row=mysql_fetch_array($result)) {
$body .= $row['products_quantity']." x ".$row['products_name']." = ".sprintf("%.2f", ($row['products_quantity'] * $row['final_price'])) . "\n";
}
$body .= "\n";
$body .= "--------------------------------------\n";
$body .= "Delivery Address\n";
$body .= "--------------------------------------\n";
$body .= "Delivery Name:: ";
$body .= $row2['delivery_name'];
$body .= "\n";
$body .= "Address 1:: ";
$body .= $row2['delivery_street_address'];
$body .= "\n";
$body .= "Address 2: ";
$body .= $row2['delivery_suburb'];
$body .= "\n";
$body .= "Address 3: ";
$body .= $row2['delivery_city'];
$body .= "\n";
$body .= "Postcode: ";
$body .= $row2['delivery_postcode'];
$body .= "\n";
$body .= "Country: ";
$body .= $row2['delivery_country'];
$body .= "\n";
// send email
$send = mail($emailto, $subject . ' ' . $ordernumber, $body, $headers);
mysql_close($conn);
// redirect to success page
if ($send){
print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.php\">";
}
else{
print "We encountered an error sending your mail";
}
?>
I'm sure you'll notice that row2 isn't defined anywhere, I did have $row2 = mysql_fetch_row($result)) but this didn't work.
Any help greatly appreciated.