Copy link to clipboard
Copied
i have a form that needs to be emailed and it as products attached to it. however i have a repeat region to list all the products but when i email it ithe email only shows the first item on the list.
below is the form set up
//emailer
// Email new tenant information
$to = 'sales@domain.com';// . ',' . '$row_rsOrder["Email"]';
//$to = $row_rsOrder["Email"];
$subject = "Your Order Details";
$message = "
<html>
<head>
<title>Dear ".$row_rsOrder['FirstName'].$row_rsOrder['LastName']." please see your Order Details Below</title>
</head>
<body>
<img src=\"http://www.website.com/images/logoBLPP.jpg\" alt=\"" />
<h2>Your B Order".$row_rsOrder['OrderID']."</h2>
<table width='800' border='0' cellspacing='0' cellpadding='0'>
<tr><td><p>Thank you for shopping below are you details of the order you have recently placed. If you have any questions please contact us</p>
<br />
</a></p>
<tr><td></td></tr></table>
<table width='980' border='1' cellspacing='0' cellpadding='10'>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Customer Name</td>
<td class='text'>".$row_rsOrder['FirstName'] . $row_rsOrder['LastName']."</td>
<td bgcolor='#E9E9E9' class='header1'>Order ID</td>
<td bgcolor='#E9E9E9' class='text'>".$row_rsOrder['OrderID']."</td>
<td bgcolor='#E9E9E9' class='header1'>Order Status</td>
<td class='text'>".$row_rsOrder['TransactResult']."</td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Email</td>
<td class='text'>".$row_rsOrder['Email']."</td>
<td bgcolor='#E9E9E9' class='header1'> </td>
<td class='text'> </td>
<td bgcolor='#E9E9E9' ><span class='header1'>Order Date</span></td>
<td class='text'>".makeDateTime($row_rsOrder['OrderDate'], '%#d %B %Y', true)."</td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Shipping Address</td>
<td class='text'><p>".$row_rsOrder['Address']."</p>
<p>".$row_rsOrder['Town']."</p>
<p>".$row_rsOrder['PostCode']."</p>
<p>".$row_rsOrder['Country']."</p>
<p> </p></td>
<td> </td>
<td> </td>
<td colspan='2' align='right' valign='bottom'><span class='header'> ORDER TOTAL:".DoFormatCurrency($row_rsOrder['Total'], 2, ',', '.', 'Ā£ ', '')."<br />
</span><span class='text'>Shipping:".DoFormatCurrency($row_rsOrder['Shipping'], 2, ',', '.', 'Ā£ ', '')."</span><span class='header'><br />
</span></td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Product ID</td>
<td bgcolor='#E9E9E9' class='header1'>Product Description</td>
<td bgcolor='#E9E9E9' colspan='2' class='header1'>Size</td>
<td bgcolor='#E9E9E9' ><span class='header1'>Quantity</span></td>
<td bgcolor='#E9E9E9' align='right'><span class='header1'>Price</span></td>
</tr>
<?php do { ?>
<tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."</td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', 'Ā£ ', '')."</td>
</tr>
<?php } while ($row_rsOrder = mysql_fetch_assoc($rsOrder)); ?>
<tr valign='top'>
<td class='text'> </td>
<td class='text'> </td>
<td colspan='2' class='text'> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: company name <email@domain.com>' . "\r\n";
$send = mail($to, $subject, $message, $headers);
Yes, ALL product information in the database were retrieved and sent to the email. Only 3 products for testing purposes.
I just tested it down to the do-while loop. The html table code after that is missing.
You have to bare in mind this is a crude test. The database set up query is not as complex as yours is so that may be why its working but certainly breaking up the 'message' is the way to go. I may try and get the products from another table tomorrow if I have time to test.
The html code and co
...Copy link to clipboard
Copied
Lets see the recordset code.
Copy link to clipboard
Copied
$var1_rsOrder = "-1";
if (isset($_GET['OrderID'])) {
$var1_rsOrder = $_GET['OrderID'];
}
mysql_select_db($database_beau, $beau);
$query_rsOrder = sprintf("SELECT * FROM beauSS13_customers, beauSS13_orderdetails, beauSS13_orders, beauSS13_products, beauSS13_Stock, beauSS13_SizeList, beauSS13_Cat WHERE beauSS13_customers.CustomerID = beauSS13_orders.CustomerID AND beauSS13_orderdetails.ProductID = beauSS13_products.ProductID AND beauSS13_orderdetails.OrderID = beauSS13_orders.OrderID AND beauSS13_orderdetails.OrderID = %s AND beauSS13_orderdetails.StockID = beauSS13_Stock.StockID AND beauSS13_SizeList.SizeID = beauSS13_Stock.SizeID AND beauSS13_Cat.catID = beauSS13_products.CatID", GetSQLValueString($var1_rsOrder, "int"));
$rsOrder = mysql_query($query_rsOrder, $beau) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
$totalRows_rsOrder = mysql_num_rows($rsOrder);
Copy link to clipboard
Copied
can anyone advise me what i need to do to get my page working please.
Copy link to clipboard
Copied
A possible reason:
The do - while loop is probably not working because you have to break out of the php and back into it again. i.e, break the $message into sections and stitch it together again $message .= "
<?php do { ?>
<?php $message = ." <tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."< /td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', 'Ā£ ', '')."</td>
</tr>";
?>
<?php } while ($row_rsOrder = mysql_fetch_assoc($rsOrder)); ?>
You can't have a block of php code which the do-while loop is within another block of php code which the $message is. You have to break out of the php to alllow the do-while loop to work and then go back into php to complete the message.
Have you tried that?
Copy link to clipboard
Copied
that makes sense. but that is showing an error,
Undefined variable: message in E:\Domains\b\website\user\htdocs\admin\order-details-sent.php on line 135
<td class='text'>".$row_rsOrder['ProductID']."</td>
i replaced the " with ' at the start and end as this was error prompting
could this be that is still causing errors
<?php do { ?>
<?php $message = .' <tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."< /td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', 'Ā£ ', '')."</td>
</tr>';
?>
<?php } while ($row_rsOrder = mysql_fetch_assoc($rsOrder)); ?>
Copy link to clipboard
Copied
Jonathan Fortis wrote:
that makes sense. but that is showing an error,
Undefined variable: message in E:\Domains\b\website\user\htdocs\admin\order-details-sent.php on line 135
<td class='text'>".$row_rsOrder['ProductID']."</td>
i replaced the " with ' at the start and end as this was error prompting
could this be that is still causing errors
<?php do { ?>
<?php $message = .' <tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."< /td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', 'Ā£ ', '')."</td>
</tr>';
?>
<?php } while ($row_rsOrder = mysql_fetch_assoc($rsOrder)); ?>
I'm not sure.
I did notice you have not escaped the second " alt=\"" in the image below which will cause the code to choke.
<img src=\"http://www.website.com/images/logoBLPP.jpg\" alt=\"" />
Copy link to clipboard
Copied
>>
I'm not sure.
I did notice you have not escaped the second " alt=\"" in the image below which will cause the code to choke.
<img src=\"http://www.website.com/images/logoBLPP.jpg\" alt=\"" />
i changed this but didnt fix it
Copy link to clipboard
Copied
hummmm ...... are OrderID and ProductID in the same table ?
Copy link to clipboard
Copied
>><?php $message = ." <tr valign='top'>
the is already a $message variable at the start of the script. will this matter?
Copy link to clipboard
Copied
>>hummmm ...... are OrderID and ProductID in the same table ?
in the beauSS13_orderdetails they are yes
Copy link to clipboard
Copied
Does the way you have it actually work anyway? What I mean is when you test the email does any information come through using the set up below:
<td class='text'>".$row_rsOrder['ProductID']."</td>
I thought that you needed to create a variable first like:
$ProductID = $row_rsOrder['ProductID'];
<td class='text'>".$ProductID."</td>
The way you have set it up you would surely need to use echo to append the information to the <td></td> cell?
echo $row_rsOrder['ProductID']
But you can't do that because that would be using a php block within a block.
Copy link to clipboard
Copied
>>Does the way you have it actually work anyway? What I mean is when you test the email does any information come through using the set up below:
the way i had it working was everything was coming through but only the 1st record of the order
Copy link to clipboard
Copied
Jonathan Fortis wrote:
>>Does the way you have it actually work anyway? What I mean is when you test the email does any information come through using the set up below:
the way i had it working was everything was coming through but only the 1st record of the order
Oh ok, it didn't work for me until I changed to the variables. You must have something different in your code which renders the way you have set it up just fine.
I've been trying to think of a way to loop through the records in a legitimate way. I'm pretty much sure you can't have the loop within the 'message' itself without breaking out of it to allow the php to work.
Copy link to clipboard
Copied
>>I've been trying to think of a way to loop through the records in a legitimate way. I'm pretty much sure you can't have the loop within >>the 'message' itself without breaking out of it to allow the php to work.
so are you saying it cant be done without a load more coding?
Copy link to clipboard
Copied
Jonathan Fortis wrote:
so are you saying it cant be done without a load more coding?
No not saying that. I just don't know if its a simple fix we are not seeing or whether the information needs to be put into an array and fetched from that or how the do-while loop can work because it needs to be part of the 'message'. But breaking the 'message' so the php can do its job seems to render the information as not part of the 'message' so it won't send.
I'm sure this will be so simple for anyone who has a good understanding. At the moment I can't get my head around how to achieve it.
It would be nic eto know though for future reference as I'm sure it will come in handy.
Copy link to clipboard
Copied
>>It would be nic eto know though for future reference as I'm sure it will come in handy.
thats what i was thinking, surely its something that i thought would have been common practice.
Copy link to clipboard
Copied
Ok well I got my do-while loop to work, it now sends all the products in the email BUT I am only using one table.
However I cant see that as an issue because you say that the first product is coming through for you so the others should.
Mine was a stupid typing error that was stopping it from working.
Copy link to clipboard
Copied
can you show me what you done? did you get all products to show in the email
Copy link to clipboard
Copied
Yes, ALL product information in the database were retrieved and sent to the email. Only 3 products for testing purposes.
I just tested it down to the do-while loop. The html table code after that is missing.
You have to bare in mind this is a crude test. The database set up query is not as complex as yours is so that may be why its working but certainly breaking up the 'message' is the way to go. I may try and get the products from another table tomorrow if I have time to test.
The html code and column database names are the same as you have. the recordeset is 'rsOrders' instead of 'rsOrder' that you used,
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_conDonations, $conDonations);
$query_rsOrders = "SELECT * FROM orders";
$rsOrders = mysql_query($query_rsOrders, $conDonations) or die(mysql_error());
$row_rsOrders = mysql_fetch_assoc($rsOrders);
$totalRows_rsOrders = mysql_num_rows($rsOrders);
//emailer
// Email new tenant information
$to = 'email@email.co.uk';// . ',' . '$row_rsOrder["Email"]';
//$to = $row_rsOrder["Email"];
$subject = "Your Order Details";
$message = "
<html>
<head>
<title>Dear ".$row_rsOrders['FirstName']." please see your Order Details Below</title>
</head>
<body>
<img src=\"http://www.website.com/images/logoBLPP.jpg\" alt=\"\" />
<h2>Your B Order".$row_rsOrders['OrderID']."</h2>
<table width='800' border='0' cellspacing='0' cellpadding='0'>
<tr><td><p>Thank you for shopping below are you details of the order you have recently placed. If you have any questions please contact us</p>
<br />
</a></p>
<tr><td></td></tr></table>
<table width='980' border='1' cellspacing='0' cellpadding='10'>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Customer Name</td>
<td class='text'>".$row_rsOrders['FirstName']."</td>
<td bgcolor='#E9E9E9' class='header1'>Order ID</td>
<td bgcolor='#E9E9E9' class='text'>".$row_rsOrders['OrderID']."</td>
<td bgcolor='#E9E9E9' class='header1'>Order Status</td>
<td class='text'>".$row_rsOrders['TransactResult']."</td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Email</td>
<td class='text'>".$row_rsOrders['Email']."</td>
<td bgcolor='#E9E9E9' class='header1'> </td>
<td class='text'> </td>
<td bgcolor='#E9E9E9' ><span class='header1'>Order Date</span></td>
<td class='text'>".$row_rsOrders['OrderDate']."</td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Shipping Address</td>
<td class='text'><p>".$row_rsOrders['Address']."</p>
<p>".$row_rsOrders['Town']."</p>
<p>".$row_rsOrders['PostCode']."</p>
<p>".$row_rsOrders['Country']."</p>
<p> </p></td>
<td> </td>
<td> </td>
<td colspan='2' align='right' valign='bottom'><span class='header'> ORDER TOTAL:".$row_rsOrders['Total']."<br />
</span><span class='text'>Shipping:".$row_rsOrders['Shipping']."</span><span class='header'><br />
</span></td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Product ID</td>
<td bgcolor='#E9E9E9' class='header1'>Product Description</td>
<td bgcolor='#E9E9E9' colspan='2' class='header1'>Size</td>
<td bgcolor='#E9E9E9' ><span class='header1'>Quantity</span></td>
<td bgcolor='#E9E9E9' align='right'><span class='header1'>Price</span></td>
</tr>";
?>
<?php do { ?>
<?php $message .=" <tr valign='top'>
<td class='text'>".$row_rsOrders['ProductID']."</td>
<td class='text'>".$row_rsOrders['Product']."</td>
<td colspan='2' class='text'>".$row_rsOrders['UnitSize']."</td>
<td><span class='text'>".$row_rsOrders['Quantity']."</span></td>
<td align='right' class='text'>".$row_rsOrders['UnitPrice']."</td>
</tr>";
?>
<?php } while ($row_rsOrders = mysql_fetch_assoc($rsOrders)); ?>
<?php $message .="
</body>
</html>";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: company name <email@domain.com>' . "\r\n";
$send = mail($to, $subject, $message, $headers);
mysql_free_result($rsOrders);
?>
Copy link to clipboard
Copied
ok i will try that and let you know how i get on
thanks for your help
Copy link to clipboard
Copied
Jonathan Fortis wrote:
ok i will try that and let you know how i get on
thanks for your help
I don't think there can be much wrong with what you have. Now I know the loop works it should work even if the information is being sourced from a dedicated 'products' table.
The fact that you get the first record returned is encouraging because it means at least the query is correct.
For my own curiosity I'll seperate the data into two tables tomorrow and see what happens.
Copy link to clipboard
Copied
>>I don't think there can be much wrong with what you have. Now I know the loop works it should work even if the information is being >>sourced from a dedicated 'products' table.
>>The fact that you get the first record returned is encouraging because it means at least the query is correct.
>>For my own curiosity I'll seperate the data into two tables tomorrow and see what happens.
no i think you are right, i need to start from scratch i think because i have tried so much now. let me know how you get on please
Copy link to clipboard
Copied
Have you looked at webassist.com and their extensions.
Although I can do a lot of coding within DW and then add extra code by hand, webassist extensions do pretty much everything and more that DW does. For instance, I know I will be able to run an extension called Universal Email and it will send an email from a recordset and I will have it working inside of 10 minutes.
I highly resommend their stuff, and you could try for two weeks with a guaranteed money back offer if you're not happy. Their tech support is also very good and quick too should you need explanation or help.
Copy link to clipboard
Copied
>>Have you looked at webassist.com and their extensions.
thanks Matthew, Ideally i need to know how to do this as i am nearly complete on this project but will take a look for future projects,. is the a free extension?