Email menggunakan database dari tabel pemesanan

Mengirimkan data pemesananan yang akan dikirimkan melalui email pemesan,
Berikut ini adalah skriptnya...


<?php
$orderid = Trim(stripslashes($_POST['ordernumber']));
$dbhost = 'localhost';
$dbuser = 'dbadmin';
$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)or die("Cannot query orders_products data" . mysql_error());

$sql2="SELECT * FROM orders WHERE orders_id = '".$orderid."'";
$result2 = mysql_query($sql2) or die("Cannot query orders data" . mysql_error());

$firstname = Trim(stripslashes($_POST['firstname']));
$lastname = Trim(stripslashes($_POST['lastname']));
$email = Trim(stripslashes($_POST['email']));
$ordernumber = Trim(stripslashes($_POST['ordernumber']));
$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: $firstname" . "\n";
$body .= "Last name: $lastname" . "\n";
$body .= "Email: $email" . "\n";
$body .= "\n--------------------------------------\n";
$body .= "Products";
$body .= "\n--------------------------------------\n";

while($row=mysql_fetch_array($result)) {
$body .= $row['products_quantity']." x ".$row['products_name']." = ".sprintf("%.2f", ($row['products_quantity'] * $row['final_price'])) . "\n";
}
while($row2=mysql_fetch_array($result2)) {
$body .= "\n--------------------------------------\n";
$body .= "Delivery Address";
$body .= "\n--------------------------------------\n";
$body .= ucwords($row2['delivery_name']) . "\n";
$body .= ucwords($row2['delivery_street_address']) ."\n";
if($row2['delivery_suburb']) {
$body .= ucwords($row2['delivery_suburb']) . "\n";
}
if($row2['delivery_city']) {
$body .= $row2['delivery_city'] . "\n";
}
$body .= strtoupper($row2['delivery_postcode']) . "\n";
$body .= $row2['delivery_country'] . "\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.";
}
?>
Source dari : http://www.webmasterworld.com/php/4276213.htm

Posting Komentar

Lebih baru Lebih lama