Hi all,
My name is Julian, I am new to this forum and I send you all greetings from really down here…New Zealand
I have an issue with my php mail function, I have asked my provider but they told me that they can`t help with coding.
I have a page, success.php which does not output to screen. A successful credit card transaction is redirected here, the MySql database is queried 2 times to get details to insert in email and an email is sent out, at the moment to me, customer and website owner. Also the session is destroyed (will clear the shopping cart) and all ends with a redirection to the next page.
The issue I have is that all 3 emails arrive in 2 copies each. This will be not so important if I will not send a copy out to customer. I noticed that all my other mail functions (which do not query the database, from other pages) are send out in one copy each.
The code with comments is bellow if you can be bothered to have a look. Any suggestions are welcome.
Thank you in advance,
Julian
<?php
/* No output to screen is generated from this page. A succesfull credit card transaction is redirected here with customers email and order number attached to url
2 database queries are executed to obtain the products in order and customers details. The retrieved data is emailed to 3 addressess at the moment:
customer`s email, me for testing purpose and owners website. All emails arrive in 2 copies. The linked pages have no email functions
*/
date_default_timezone_set("Pacific/Auckland");
//database credentials
include ("../cp/kiaora.dora");
include ("../cp/db.dora");
//obtain customer details
$sql = "SELECT email, fname, lname, phone, street, suburb, city, postCode, country, fnameShip, lnameShip, streetShip, suburbShip, cityShip, postCodeShip, countryShip FROM customers WHERE email='" . $_GET['email'] . "'";
$result = mysql_query($sql) or die(mysql_error());
while ($results = mysql_fetch_array($result)) {
$orderno = $results['orderno'];
$email = $results['email'];
$fname = $results['fname'];
$lname = $results['lname'];
$phone = $results['phone'];
$street = $results['street'];
$suburb = $results['suburb'];
$city = $results['city'];
$postCode = $results['postCode'];
$country = $results['country'];
$fnameShip = $results['fnameShip'];
$lnameShip = $results['lnameShip'];
$phoneShip = $results['phoneShip'];
$streetShip = $results['streetShip'];
$suburbShip = $results['suburbShip'];
$cityShip = $results['cityShip'];
$postCodeShip = $results['postCodeShip'];
$countryShip = $results['countryShip'];
}
//start creating the email`s body
$orderItems = "Status: Payment received, thank you.<br /><br /><b>Bill to</b><br />$fname $lname<br />Address: $street $suburb<br />$city $postCode<br />Country: $country<br /><br /><br /><b>Ship to</b><br />$fnameShip $lnameShip<br />Address: $streetShip $suburbShip<br />$cityShip $postCodeShip<br />Country: $countryShip<br /><br />";
//items in order query
$sql = "SELECT orderno, item_id, item_name, item_price, item_qty, total FROM shopping_cart WHERE orderno='" . $_GET['orderno'] . "'";
$result = mysql_query($sql) or die(mysql_error());
$orderItems .= "<p>Items in order</p><table width=\\"90%\\" border=\\"0\\" cellpadding=\\"5\\"><tbody><tr><td><b>Item</b></td><td><b>Price</b></td><td><b>Quantity</b></td></tr><tr><td colspan=\\"3\\"><hr/></td></tr>";
while ($items = mysql_fetch_array($result)) {
$orderno = $items['orderno'];
$name = $items['item_name'];
$price = $items['item_price'];
$qty = $items['item_qty'];
$total = $items['total'];
//define shippingCharge to add it to email body if there is post charge
$shippingCharge="";
//if total different price of all items together will set shipping charge to a message that $ 5 from total is shipping charge
if($price!==$total){$shippingCharge="(Includes 5 \\$ shipping charge)";}
//adding the order items to email and finishing the email
$orderItems .= "<tr><td>$name</td><td>$price NZD</td><td>$qty</td></tr>";
}$orderItems .= "</table><br /><strong>Total: $total \\$ $shippingCharge</strong><p>Your order will be shipped next business day.<br />Any enquiries contact <a href=\\"mailto:orders@everhealthpharmacy.co.nz?Subject=Order $orderno\\" title=\\"Contact us\\">orders@everhealthpharmacy.co.nz</a><br />Phone: 07 849 3805 Please quote order number $orderno</p><em>The team at Everhealth Pharmacy</em>";
//getting new zealand times
$date = date("l, F jS, Y");
$time = date("h:i A");
//email to customer
$to = $_GET['email'];
$subject = "Everlife Pharmacy ORDER NO. $orderno placed. Credit Card Order";
$message = $orderItems;
$headers = "From: [email]orders@everhealthpharmacy.co.nz[/email]\\r\
";
$headers .= "Content-type: text/html\\r\
";
mail($to, $subject, $message, $headers);
//email to developer
$to = "julianstefan@focusdesign.biz";
mail($to, $subject, $message, $headers);
//email to website owner
$to = "orders@everhealthpharmacy.co.nz";
mail($to, $subject, $message, $headers);
//destroy session to clear the shopping card
unset ($_COOKIE["PHPSESSID"]);
setcookie("PHPSESSID", "", time() - 3600, "/");
//redirection to next page
header("Location:http://www.everhealthpharmacy.co.nz?cc=1");
?>