// Get all the manufacturers emails to be sent to
// Must have an email address and have manufacturers_send_email set to 1
$manufacturers_email_query = tep_db_query("select distinct m.manufacturers_email, m.manufacturers_name FROM manufacturers m, orders_products o, products p where p.manufacturers_id=m.manufacturers_id and p.products_id=o.products_id and o.orders_id='" . $oID . "' and m.manufacturers_send_email=1 ORDER BY m.manufacturers_id");
while ($manufacturers_email_list= tep_db_fetch_array($manufacturers_email_query)) {
$the_email=$manufacturers_email_list['manufacturers_email'];
$the_name=$manufacturers_email_list['manufacturers_name'];
$email_message = '<br>To: <b>' . $the_name . ' - ' . $the_email .
'</b> From: <b>' . STORE_NAME . '</b><br><br><br><br>Please deliver to:<br>' .
$delivery_address_list['customers_company'] .'<br>' .
$delivery_address_list['customers_name'] .'<br>' .
$delivery_address_list['customers_street_address'] .'<br>' .
$delivery_address_list['customers_postcode'] . ' ' . $delivery_address_list['customers_city'] . '<br>' ;
// Get all the products for a manufacture to be included in the email
$manufacturers_email_products_query = tep_db_query("select o.orders_id, m.manufacturers_id, m.manufacturers_name, m.manufacturers_email, o.products_name, o.products_model, o.products_id, o.products_price, o.products_quantity, o.orders_products_id FROM manufacturers m, orders_products o, products p where p.manufacturers_id=m.manufacturers_id and o.products_id=p.products_id and o.orders_id='" . $oID . "' and m.manufacturers_email='" . $the_email . "' order by o.products_name");
$email_message = $email_message .
'<table width="75%" border=1 cellspacing="0" cellpadding="0">
<tr><td>Qty:</td><td>Productname:</td><td>Productmodel:</td><td>Price:</td></tr>' ;
while ($manufacturers_email_products= tep_db_fetch_array($manufacturers_email_products_query)) {
$email_message = $email_message . '<tr><td>' . $manufacturers_email_products['products_quantity'] . '</td><td>' . $manufacturers_email_products['products_name'] . '</td><td>' . $manufacturers_email_products['products_model'] .
'</td><td>' . $manufacturers_email_products['products_price'] . '</td></tr>';
$current_products_id=$manufacturers_email_products['orders_products_id'];
$manufacturers_email_products_attributes_query = tep_db_query("select distinct opa.products_options_values from orders_products_attributes opa, orders o where opa.orders_id='" . $oID . "' and opa.orders_products_id='" .$current_products_id . "'");
while ($manufacturers_email_products_attributes= tep_db_fetch_array($manufacturers_email_products_attributes_query)) {
$email_message = $email_message . '<tr><td> </td><td colspan=3>'. $manufacturers_email_products_attributes['products_options_values'] .'</td></tr>';
}
$email_message = $email_message . '<br>';
}
$email_message = $email_message . '</table><br><HR><br>';
//send the email