2012-07-01 130 views
0

我使用Mozilla Thunderbird中使用XAMPP - 汞,Apache,MySQL和電子郵件不發送正確

問題是,當我爲了一個產品,它發出的訂單電子郵件一切就緒。它看起來像這樣一種產品:

Order date and time: July 1, 2012, 11:04 am 
Thank you for your order at our online shop! 
Your order information: 


    Product ID: 1991001 
    Brand: Razer 
    Model: Mamba Elite Wireless Gaming Mouse 
    Price per item: 129.99 
    Amount of item: 1 
    Total cost: 129.99 
    _________________________________________________| 
    1To follow your odertracking please remember your order ID and customer ID 
    Order ID: 116 
    Customer ID: 6 
    Link to track your order: Ordertracking system 

當我訂購5個款產品,它只會顯示4個產品中的電子郵件,並期待這樣的:

Order date and time: July 1, 2012, 11:08 am 
Thank you for your order at our online shop! 
Your order information: 


Product ID: 1991001 
Brand: Razer 
Model: Mamba Elite Wireless Gaming Mouse 
Price per item: 129.99 
Amount of item: 1 
Total cost: 129.99 
_________________________________________________| 
1 Product ID: 1991002 
Brand: Razer 
Model: Imperator Expert Ergonomic Gaming Mouse 
Price per item: 79.99 
Amount of item: 1 
Total cost: 79.99 
_________________________________________________| 
2 Product ID: 1991003 
Brand: Razer 
Model: Orochi Elite Mobile Gaming Mouse 
Price per item: 79.99 
Amount of item: 3 
Total cost: 239.96999999999997 
_________________________________________________| 
3 Product ID: 1991004 
Brand: Razer 
Model: Expert Ambidextrous Gaming Mouse 
Price per item: 79.99 
Amount of item: 1 
T 

我沒有看到第5產品也看不到: To follow your odertracking please remember your order ID and customer ID Order ID: 116 Customer ID: 6 Link to track your order: Ordertracking system

爲什麼以及如何解決這個問題?

下面是電子郵件的代碼。 email.php,最後你看到的變種轉儲outpu $to = $email;

<?php 
//var_dump($_GET); 

//collect all information 
$name = $_GET["name"]; 
$surname = $_GET["surname"]; 
$city = $_GET["city"]; 
$postalcode = $_GET["postalcode"]; 
$phonenumber = $_GET["phonenumber"]; 
$email = $_GET["email"]; 

$i = 1; 
while (isset($_GET["Product_ID_".$i])) { 
    $productid = $_GET["Product_ID_".$i]; 
    $brand = $_GET["Brand_".$i]; 
    $model = $_GET["Model_".$i]; 
    $price = $_GET["Price_".$i]; 
    $amount = $_GET["Amount_products_".$i]; 
    $totalcost = $_GET["Total_cost_".$i]; 
    $i++; 
} 

$image = "includes/images/mouse_4.jpg"; 


$date = date("F j, Y, g:i a"); 



//connect to database 
$connection = mysql_connect("localhost","root","") or die ("Can't connect"); 
mysql_select_db("shoppingcart", $connection) or die ("Can't connect"); 

//check if already customer 
$result = mysql_query("SELECT * FROM customer WHERE email='$email'"); 
$rows = mysql_num_rows($result); 


    if ($rows) 
    { 
     echo '<br>Welcome back ' . $name .' '. $surname. '<br>'; 
    } 
    else 
    { 
     //if new customer, add to database 
     $customer = "INSERT INTO customer (customerid, name, surname, email, city, postalcode, phonenumber) VALUES ('', '$name', '$surname', '$email', '$city', '$postalcode', '$phonenumber')"; 
     if (!mysql_query($customer,$connection)) 
     { 
      die('Error: ' . mysql_error()); 
      echo "Sorry, there was an error"; 
     } 
     echo "New customer added" . "<br />"; 
     echo '<br>Welcome as our new customer ' . $name . ' '. $surname; 

     mysql_close($connection); 
    } 

//connect to database 
$connection = mysql_connect("localhost","root","") or die ("Can't connect"); 
mysql_select_db("shoppingcart", $connection) or die ("Can't connect"); 


//get customer id 
$res = mysql_query("SELECT customerid FROM customer WHERE email='$email'"); 
while($row=mysql_fetch_array($res)) 
{ 
$customerid=$row['customerid']; 
} 
    //add new ordertracking 
    $ordertracking = "INSERT INTO `ordertracking` (orderid, customerid, email, progress, date) VALUES ('', '$customerid', '$email', 'Pending', '$date')"; 
    if (!mysql_query($ordertracking,$connection)) 
     { 
      die('Error: ' . mysql_error()); 
      echo "Sorry, there was an error"; 
     } 
     echo "New order added" . "<br />"; 

     mysql_close($connection); 

//connect to database 
$connection = mysql_connect("localhost","root","") or die ("Can't connect"); 
mysql_select_db("shoppingcart", $connection) or die ("Can't connect"); 

//get order id 
$vol = mysql_query("SELECT orderid FROM ordertracking WHERE email='$email'"); 
while($volume=mysql_fetch_array($vol)) 
{ 
$orderid = $volume['orderid']; 
} 
    // add new order 
    $order = "INSERT INTO `order` (orderid, customerid, productid, brand, model, price, amount, totalcost, image) VALUES ('$orderid', '$customerid', '$productid', '$brand' , '$model', '$price', '$amount', '$totalcost', '$image')"; 
    if (!mysql_query($order,$connection)) 
     { 
      die('Error: ' . mysql_error()); 
      echo "Sorry, there was an error"; 
     } 
     echo "New order added" . "<br />"; 

     mysql_close($connection); 


$to = $email; 
$subject = "Order information of: "; 

$headers = "From: " . "[email protected]" . "\r\n"; 
$headers .= "Reply-To: ". "[email protected]" . "\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

$message = '<html><body>'; 
$message .= '<h1>Dear ' . $name . ' ' . $surname . ',</h1>' . '<br />'; 
$message .= 'Order date and time: ' . $date . '<br />'; 
$message .= 'Thank you for your order at our online shop!' . '<br />'; 
$message .= 'Your order information: ' . '<br /><br /><br />'; 
$i = 1; 
while (isset($_GET["Product_ID_".$i])) { 
    $productid = $_GET["Product_ID_".$i]; 
    $brand = $_GET["Brand_".$i]; 
    $model = $_GET["Model_".$i]; 
    $price = $_GET["Price_".$i]; 
    $amount = $_GET["Amount_products_".$i]; 
    $totalcost = $_GET["Total_cost_".$i]; 

    $message .= ' Product ID: ' . $productid . "<br />" . 
       'Brand: '. $brand . "<br />" . 
       'Model: ' . $model . "<br />" . 
       'Price per item: ' . $price . "<br />" . 
       'Amount of item: ' . $amount . "<br />" . 
       'Total cost: ' . $totalcost . "<br />" . 
       '_________________________________________________| ' . "<br />" . 
    $i++; 
} 
$message .= 'To follow your odertracking please remember your order ID and customer ID' . '<br />'; 
$message .= 'Order ID: ' . $orderid . '<br />'; 
$message .= 'Customer ID: ' . $customerid . '<br />'; 
$message .= 'Link to track your order: ' . '<a href="http://localhost/school/shoppingcart/ordertracking.php">Ordertracking system</a>' . '<br />'; 

$message .= '</body></html>'; 

mail($to, $subject, $message, $headers); 

?> 
<meta http-equiv="REFRESH" content="3;ordertracking.php"> 

編輯:

array(38) { ["Product_ID_1"]=> string(7) "1991001" ["Brand_1"]=> string(5) "Razer" ["Model_1"]=> string(33) "Mamba Elite Wireless Gaming Mouse" ["Price_1"]=> string(6) "129.99" ["Amount_products_1"]=> string(1) "1" ["Total_cost_1"]=> string(6) "129.99" ["Product_ID_2"]=> string(7) "1991002" ["Brand_2"]=> string(5) "Razer" ["Model_2"]=> string(39) "Imperator Expert Ergonomic Gaming Mouse" ["Price_2"]=> string(5) "79.99" ["Amount_products_2"]=> string(1) "1" ["Total_cost_2"]=> string(5) "79.99" ["Product_ID_3"]=> string(7) "1991003" ["Brand_3"]=> string(5) "Razer" ["Model_3"]=> string(32) "Orochi Elite Mobile Gaming Mouse" ["Price_3"]=> string(5) "79.99" ["Amount_products_3"]=> string(1) "1" ["Total_cost_3"]=> string(5) "79.99" ["Product_ID_4"]=> string(7) "1991004" ["Brand_4"]=> string(5) "Razer" ["Model_4"]=> string(32) "Expert Ambidextrous Gaming Mouse" ["Price_4"]=> string(5) "79.99" ["Amount_products_4"]=> string(1) "1" ["Total_cost_4"]=> string(5) "79.99" ["Product_ID_5"]=> string(7) "1991005" ["Brand_5"]=> string(5) "Razer" ["Model_5"]=> string(62) "Battlefield 3â„¢ Razer Imperator Expert Ergonomic Gaming mouse" ["Price_5"]=> string(5) "79.99" ["Amount_products_5"]=> string(1) "1" ["Total_cost_5"]=> string(5) "79.99" ["name"]=> string(1) "s" ["surname"]=> string(1) "s" ["city"]=> string(1) "s" ["postalcode"]=> string(1) "s" ["phonenumber"]=> string(1) "s" ["email"]=> string(17) "[email protected]" ["x"]=> string(2) "85" ["y"]=> string(2) "12" } 
+1

看來你遇到了一些錯誤終止該腳本。我只能建議iclude error_reporting(-1); ini_set('display_errors','stdout');在腳本的頂部並檢查它的投訴 – karka91

+1

您是否通過GET查詢字符串傳遞所有產品信息?查詢字符串的最大長度是瀏覽器特定的。如果你沒有對值進行編碼,特別是字符串,就像<?php ...?下的模型和品牌 – freefaller

+0

一樣,它也會失敗。什麼都沒發生。我沒有看到任何錯誤。我在哪裏必須查看錯誤? – MOTIVECODEX

回答

1

我認爲問題出在通過查詢字符串的所有信息的傳遞。

相反,你應該通過POST基於形式發送它,然後用$_POST

如果你已經在使用一種形式,那麼就改變method屬性POST

+0

使用post而不是get只會給出錯誤,整個腳本根本無法使用 – MOTIVECODEX

+1

你能否解釋一下當我說使用'$ _POST'時它會如何導致錯誤? – freefaller

+1

他可能沒有改變$ _GET至$ _ POST腳本 – karka91

相關問題