电子邮件未正确发送

时间:2012-07-01 09:14:33

标签: php html email

我正在使用Mozilla Thunderbird和xampp - mercury,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,最后你看到$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: " . "postmaster@localhost" . "\r\n";
$headers .= "Reply-To: ". "postmaster@localhost" . "\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">

编辑var dump outpu:

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) "klant-x@localhost" ["x"]=> string(2) "85" ["y"]=> string(2) "12" } 

1 个答案:

答案 0 :(得分:1)

我认为问题在于通过查询字符串传递所有信息。

相反,您应该通过基于POST的表单发送,然后使用$_POST

如果您已在使用表单,则只需将method属性更改为POST

相关问题