Jump to content

php mail


nibbo

Recommended Posts

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: sales@fabricadabra.net\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
Share on other sites

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 . "&nbsp&nbsp&nbspDate 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: sales@fabricadabra.net\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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.