Hi ppl,
I have a problem with this code. the two mail functions for "You Sold..." and "You Did Not Sell.." are being delivered fine. However all the others are being sent as junk.
The only difference I can see is that the bottom two are the only that are not in an extra iteration.
Any idea whats going on?
Thanks,
Asa
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Auction.Beta</title>
</head>
<body>
<?
include("connect.php");
//$cron = mysql_query("SELECT * FROM item WHERE auction_end BETWEEN DATE_SUB(now(), INTERVAL 10 MINUTE) AND now()"); // run items * 10 mins
$cron = mysql_query("SELECT * FROM item "); // run all items
while($item = mysql_fetch_row($cron))
{
// mail the buyers
// if the remaining quantity is greater than 1, process end of multiple item auction
if ($item[26]>1)
{
// get the lowest winning bid
$quantity_remain = $item[26];
$bidders = mysql_query("SELECT * FROM bid_history WHERE item_id='$item[0]' ORDER BY current_bid DESC");
while($bid_row=mysql_fetch_row($bidders))
{
if ($quantity_remain>=1)
$low_price = $bid_row[3];
$quantity_remain = $quantity_remain - $bid_row[5];
}
// email winners
$quantity_remain = $item[26];
$bidders = mysql_query("SELECT * FROM bid_history WHERE item_id='$item[0]' ORDER BY current_bid DESC");
while($bid_row=mysql_fetch_row($bidders))
{
// email full winners
if ($quantity_remain >= $bid_row[5])
{
$to = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$bid_row[2]'"));
$body = "beta test: mailing $bid_row[2], you have won multiple item auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $bid_row[2] [$to[0]], you have won multiple item auction: $item[1] [# $item[0]]<br>";
mail("$to[0]","You Full Won Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
// email partial winner
elseif ($quantity_remain>=1)
{
$to = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$bid_row[2]'"));
$body = "beta test: mailing $bid_row[2], you have part won multiple item auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $bid_row[2] [$to[0]], you have part won multiple item auction: $item[1] [# $item[0]]<br>";
mail("$to[0]","You Part Won Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
else
{
// email losers
$to = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$bid_row[2]'"));
$body = "beta test: mailing $bid_row[2], you have not won multiple item auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $bid_row[2] [$to[0]], you have not won multiple item auction: $item[1] [# $item[0]]<br>";
mail("$to[0]","You Have Not Won Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
// reduce the quantity remaining
$quantity_remain = $quantity_remain - $bid_row[5];
}
}
else
{
$high_bid = mysql_fetch_row(mysql_query("SELECT * FROM bid_history WHERE item_id='$item[0]' ORDER BY current_bid DESC"));
if ($high_bid)
{
// Notify the highest bidder
$to = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$high_bid[2]'"));
$body = "beta test: mailing $high_bid[2], you have won single item auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $high_bid[2] [$to[0]], you have won single item auction: $item[1] [# $item[0]]<br>";
mail("$to[0]","You Won Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
// email lost auction
$next_bids = mysql_query("SELECT * FROM bid_history WHERE item_id='$item[0]' ORDER BY current_bid DESC");
if (mysql_num_rows($next_bids)>1)
{
mysql_data_seek($next_bids,1);
while($next_bid=mysql_fetch_row($next_bids))
{
$to = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$next_bid[2]'"));
$body = "beta test: mailing $next_bid[2], you have lost single item auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $next_bid[2] [$to[0]], you have lost single item auction: $item[1] [# $item[0]]<br>";
mail("$to[0]","You Did Not Win Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
}
}
// mail the seller
$won = mysql_num_rows(mysql_query("SELECT item_id FROM bid_history WHERE item_id='$item[0]'"));
if ($won>=1)
{
$seller_mail = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$item[9]'"));
$body = "beta test: mailing $item[9], you have sold an item at auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $item[9] [$seller_mail[0]], you have sold an item at auction: $item[1] [# $item[0]]<br>";
mail("$seller_mail[0]","You Sold Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
else
{
$seller_mail = mysql_fetch_row(mysql_query("SELECT email FROM login WHERE userid='$item[9]'"));
$body = "beta test: mailing $item[9], you did not sell an item at auction: $item[1] [# $item[0]]\n";
$from = "asa@argyllnewmedia.co.uk";
$mailheader = "From: $from\r\n";
echo "beta test: mailing $item[9] [$seller_mail[0]], you did not sell an item at auction: $item[1] [# $item[0]]<br>";
mail("$seller_mail[0]","You Did Not Sell Auction.Beta Item: $item[1] [# $item[0]]","$body","$mailheader");
}
}
?>
</body>
</html>