2012-07-01 169 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

相关问题