nibbo Posted March 17, 2008 Share Posted March 17, 2008 Heeeelp! I have a webpage that emails users; the trouble is they receive multiple copies of the same email. Code is simply: $MailSent = mail($Quote->CustomerEmail, "Fabricadabra Quotation", $Message, "From: [email protected]\r\nContent-type: text/html; charset=uk-ascii") or die("<h2 style='color:red'>Sorry but we were unable to send this email. " .... It's not in a loop and the number of times it is output is usually 3 but sometimes up to 6!! I have done a search but nothing like this found. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/ Share on other sites More sharing options...
matto Posted March 17, 2008 Share Posted March 17, 2008 you may need to post the entire script...... Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493776 Share on other sites More sharing options...
teng84 Posted March 17, 2008 Share Posted March 17, 2008 yes post your code Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493779 Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 post the code please your looping somewere or the page is looping it self........ Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493782 Share on other sites More sharing options...
nibbo Posted March 17, 2008 Author Share Posted March 17, 2008 Thanks all; here is the function I am using. I have triple checked the page code and I am certain the page is not looping and the function itself can only be called once. function UpdateQuoteAndEmail() { OpenDatabase(); $sql = "UPDATE orderheader SET OrderStatus = '1' WHERE OrderNumber = '" . $_POST['QuotationNumber'] . "'"; mysql_query($sql) or die("<h2>Database update failed: " . mysql_error() . "<br>" . $sql . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>"); foreach ($_POST as $key => $value) { if ((substr($key, 0, 9) == "UnitPrice") && ($value != "")) { $sql = "UPDATE orderline SET Price = '" . $value . "', LineStatus = '1' " . "WHERE OrderNumber = '" . $_POST['QuotationNumber'] . "' AND LineNumber = '" . substr($key, 9) . "'"; mysql_query($sql) or die("<h2>Database update failed: " . mysql_error() . "<br>" . $sql . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>"); } } $sql = "SELECT * FROM orderheader WHERE OrderNumber = '" . $_POST['QuotationNumber'] . "'"; $Quotes = mysql_query($sql) or die("<h1>Database access failure - " . mysql_error() . "<br>" . $sql . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>"); $Quote = mysql_fetch_object($Quotes); $Message .= "<html xmlns='http://www.w3.org/TR/REC-html40' xml:lang='en'>\n"; $Message .= "<head><meta http-equiv=Content-Type content='text/html; charset=iso-8859-1'><style>td {font-size:1em}</style></head>\n"; $Message .= "<body>\n"; $Message .= "<table width='800'>\n"; $Message .= "<tr><td align='center'><h1>Your quotation from FABRICADABRA</h1></td></tr>\n"; $OrderYYYY = substr($Quote->OrderDate, 0, 4); $OrderMM = substr($Quote->OrderDate, 5, 2); $OrderDD = substr($Quote->OrderDate, 8, 2); $Message .= "<tr><td align='center'><h2>Quotation reference: Q" . $Quote->OrderNumber . "   Date Requested: " . date('d/m/Y', mktime(0,0,0,$OrderMM,$OrderDD,$OrderYYYY)) . "</td></tr>\n"; $Message .= "<tr><td><br><br>Dear " . $Quote->CustomerName . ",</td></tr>\n"; $Message .= "<tr><td><br>Thank you for your recent quotation request.\n"; $Message .= "Please find below our best price for the items you were interested in.\n"; $Message .= "<br>This Quote is valid for 30 days and will not be available after <b>" . date('d/m/Y', mktime(0,0,0,$OrderMM,$OrderDD+30,$OrderYYYY)) . ".</b></td></tr>\n"; $Message .= "<tr><td align='center'><br><br><table cellpadding='10' border='3'>\n"; $Message .= "<tr><td>Description</td><td>Sale Unit</td><td>Quantity</td><td>Unit Price</td><td>Line Total</td></tr>\n"; $sql = "SELECT * FROM orderline WHERE OrderNumber = '" . $Quote->OrderNumber . "' AND LineType = 'Q'"; $QuoteLines = mysql_query($sql) or die("<h1>Database access failure - " . mysql_error() . "<br>" . $sql . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>"); $QuoteTotal; while ($QuoteLine = mysql_fetch_object($QuoteLines)) { $sql = "SELECT * FROM stocklist WHERE StockNumber = '" . $QuoteLine->StockNumber . "'"; $StockItem = mysql_query($sql) or die("<h1>Database access failure - " . mysql_error() . "<br>" . $sql . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>"); $Item = mysql_fetch_object($StockItem); $LineTotal = $QuoteLine->Quantity * $QuoteLine->Price; $QuoteTotal += $LineTotal; $Message .= "<tr><td>" . $Item->ShortDescription; if ($QuoteLine->Variant != "") {$Message .= " (" . $QuoteLine->Variant . ")"; } $Message .= "</td>"; $Message .= "<td align='center'>" . $Item->Unit . "</td>"; $Message .= "<td align='right'>" . $QuoteLine->Quantity . "</td>"; $Message .= "<td align='right'>£" . number_format($QuoteLine->Price,2, '.', '') . "</td>"; $Message .= "<td align='right'>£" . number_format($LineTotal,2, '.', '') . "</td></tr>\n"; } $Message .= "</table>\n"; $Message .= "<tr><td><br><br>All prices quoted are inclusive of VAT</td></tr>\n"; if ($QuoteTotal > 149.99) { $Message .= "<tr><td>Postage would be FREE for this order.</td></tr>\n"; } else { $Message .= "<tr><td>As this order is for less than £150 a postage cost of £10 would be required.</td></tr>\n"; } $Message .= "<tr><td>If you wish to procede with this purchase please go to " . "<a href='www.fabricadabra.net'>fabricadabra</a> and click on 'My Quotations'.</td></tr>\n"; $Message .= "<tr><td>If you have any further queries regarding this quote feel free to reply to this email.</td></tr>\n"; $Message .= "<tr><td>Thank you for allowing Fabricadabra the oportunity to provide you with a quotation.</td></tr>\n"; $Message .= "</table></body></html>\n"; CloseDatabase(); $MailSent = mail($Quote->CustomerEmail, "Fabricadabra Quotation", $Message, "From: [email protected]\r\nContent-type: text/html; charset=uk-ascii") or die("<h2 style='color:red'>Sorry but we were unable to send this email. " . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>" . "<br><br><br>" . $Message); $TimesSent++; OpenDatabase(); $sql = "UPDATE orderline SET LineStatus = '2' WHERE OrderNumber = '" . $Quote->OrderNumber . "' AND LineType = 'Q'"; $QuoteLines = mysql_query($sql) or die("<h2>Database update failure - " . mysql_error() . "<br>" . $sql . "<br>If this problem persists please contact " . "<a href='http://www.dotnetlimited.net/dotNETMail.php' target='_blank'><span class='dotNET'>dotNet Limited</span></a>"); CheckOrder(); CloseDatabase(); $_POST['Action'] = ""; $_POST['QuotationNumber'] = ""; } Thanks again Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493789 Share on other sites More sharing options...
teng84 Posted March 17, 2008 Share Posted March 17, 2008 try to echo something above that mail function and check how many times it prints sorry man i really find it hard to understand your code. and wait if your mail function is inside this function UpdateQuoteAndEmail() you maybe calling that function more than once Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493798 Share on other sites More sharing options...
nibbo Posted March 17, 2008 Author Share Posted March 17, 2008 Thanks Teng84; I put an echo just befor the mail statement and it only displays once. The function can definately only be called once also. Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493808 Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 Could the whole script be executing many times? (Like pressing refresh?) Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493812 Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 $Quote = mysql_fetch_object($Quotes); got to be one off your objects check Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493825 Share on other sites More sharing options...
nibbo Posted March 17, 2008 Author Share Posted March 17, 2008 Verry wierd... I have used a session variable to collate ther number of times the page loads and it does seem to be loading more than once. Thanks for all of the suggestions I will now look at my page logic. Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493832 Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 post the code please your looping somewere or the page is looping it self........ said that hours ago m8....... Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493854 Share on other sites More sharing options...
nibbo Posted March 17, 2008 Author Share Posted March 17, 2008 So you did redarrow and I though 'Oh no it isnt' Anyway, turns out there is a javascripd form validation that can submit the page more than once :'( All sorted now so thanks to all for their suggestions. How do I set this thread to SOLVED so that other members don't waste time reading this? Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493860 Share on other sites More sharing options...
redarrow Posted March 17, 2008 Share Posted March 17, 2008 the solved button fell off the nav bar sorry.......... Link to comment https://forums.phpfreaks.com/topic/96482-php-mail/#findComment-493862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.