Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Help me find syntax error

the mail() function

Moderators: macek, egami, gesf

Help me find syntax error

Postby sccot » Wed Jul 13, 2011 4:13 am

Hey guys

im making and order confirmation email send out, but i'm getting this syntax error with unexpected } on line 104. I think this is because loop 'for {' where i want to generate items ordered into the table. can anyone help me find out what is wrong or how can i add loop into the email message body. thanks

Code: Select all
<?php
require_once 'library/config.php';

// if no order id defined in the session
// redirect to main page
if (!isset($_SESSION['orderId'])) {
   header('Location: ' . WEB_ROOT);
   exit;
}

$pageTitle   = 'Checkout Completed Successfully';
require_once 'include/header.php';
require_once 'library/cart-functions.php';


// send notification email
if ($shopConfig['sendOrderEmail'] == 'y') {
   $subject = "[New Order] " . $_SESSION['orderId'];
   $email   = $shopConfig['email'];
   $message = "You have a new order. Check the order detail here \n http://" . $_SERVER['HTTP_HOST'] . WEB_ROOT . 'admin/order/index.php?view=detail&oid=' . $_SESSION['orderId'] ;
   mail($email, $subject, $message, "From: $email\r\nReturn-path: $email");
}
$order_id = $_SESSION['orderId'];
$sql = "SELECT od_email FROM tbl_order WHERE od_id = $order_id";
$result = dbQuery($sql);
$row = dbFetchAssoc($result);
extract($row);
$status="Paid";
$sql = "UPDATE tbl_order
            SET od_status = '$status', od_last_update = NOW()
            WHERE od_id = $orderId";
    $result = dbQuery($sql);

$sql = "SELECT pd_name, pd_price, od_qty
       FROM tbl_order_item oi, tbl_product p
      WHERE oi.pd_id = p.pd_id and oi.od_id = $orderId
      ORDER BY od_id ASC";

$result = dbQuery($sql);
$orderedItem = array();
while ($row = dbFetchAssoc($result)) {
   $orderedItem[] = $row;
}


// get order information
$sql = "SELECT od_date, od_last_update, od_status, od_shipping_first_name, od_shipping_last_name, od_shipping_address1,
               od_shipping_address2, od_shipping_phone, od_shipping_state, od_shipping_city, od_shipping_postal_code, od_shipping_cost,
            od_payment_first_name, od_payment_last_name, od_payment_address1, od_payment_address2, od_payment_phone,
            od_payment_state, od_payment_city , od_payment_postal_code,
            od_memo
       FROM tbl_order
      WHERE od_id = $orderId";

$result = dbQuery($sql);
extract(dbFetchAssoc($result));
   

$subject_c = "Your purchased items on our website";
   $email_c   = $od_email;
   $headers  = 'MIME-Version: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $headers .= 'Bcc: email@gmail.com' . "\r\n";
   $message_c = "<p>&nbsp;</p>

    <table width=\"550\" border=\"1\"  align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"detailTable\">
        <tr>
            <td colspan=\"2\" align=\"center\" id=\"infoTableHeader\">Order Detail</td>
        </tr>
        <tr>
            <td width=\"150\" class=\"label\">Order Number</td>
            <td class=\"content\">" . $orderId . "</td>
        </tr>
        <tr>
            <td width=\"150\" class=\"label\">Order Date</td>
            <td class=\"content\">". $od_date . "</td>
        </tr>
        <tr>
            <td class=\"label\">Status</td>
            <td class=\"content\">" . $orderId ."></td>
        </tr>
    </table>
   
   <p>&nbsp;</p>
<table width=\"550\" border=\"0\"  align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"detailTable\">
    <tr id=\"infoTableHeader\">
        <td colspan=\"3\">Ordered Item</td>
    </tr>
    <tr align=\"center\" class=\"label\">
        <td>Item</td>
        <td>Unit Price</td>
        <td>Total</td>
    </tr>".
   
$numItem  = count($orderedItem);
$subTotal = 0;
for ($i = 0; $i < $numItem; $i++) {
   extract($orderedItem[$i]);
   $subTotal += $pd_price * $od_qty;
"<tr class=\"content\">
        <td>". $od_qty . " x " . $pd_name ."</td>
        <td align=\"right\">". displayAmount($pd_price). "</td>
        <td align=\"right\">". displayAmount($od_qty * $pd_price). "</td>
    </tr>". } ."</table>";
   
   
   
   
   mail($email_c, $subject_c, $message_c, $headers);
require_once 'include/top.php'; ?>
 <div class="main">
 <table width="851"><tr><td valign="top" id="leftnav">
   
<ul>
<li><a href="/eshop/">&laquo; eShop</a></li></ul></td><td>
<p>&nbsp;</p><table width="500" border="0" align="center" cellpadding="1" cellspacing="0" class="cat">
   <tr>
      <td align="left" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
               <td align="center"> <p>&nbsp;</p>
                        <h2>Thank you for shopping with us!</h2> <p>We will send the purchased
                            item(s) right after your payment is completed. Your order number is: <b><?php echo $_SESSION['orderId']; ?></b>. Order confirmation email was sent to <b><?php echo $od_email; ?></b></p>
                  <p>&nbsp;</p></td>
            </tr>
         </table></td>
   </tr>
</table>
<br>
<br>
 
 </td><td  valign="top" width="130" id="mcart">
  <?php require_once 'include/miniCart.php'; ?></td></tr></table>
 
 

<?php
require_once 'include/footer.php';
unset($_SESSION['orderId']); ?>
sccot
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jul 13, 2011 4:04 am

Re: Help me find syntax error

Postby gandahar » Thu Jul 14, 2011 2:08 am

Code: Select all
for ($i = 0; $i < $numItem; $i++) {
   extract($orderedItem[$i]);
   $subTotal += $pd_price * $od_qty;
"<tr class=\"content\">
        <td>". $od_qty . " x " . $pd_name ."</td>
        <td align=\"right\">". displayAmount($pd_price). "</td>
        <td align=\"right\">". displayAmount($od_qty * $pd_price). "</td>
    </tr>". } ."</table>";


missing echo or a $var
I think you can't close a braket like this, try this :
Code: Select all
for ($i = 0; $i < $numItem; $i++) {
   extract($orderedItem[$i]);
   $subTotal += $pd_price * $od_qty;
echo "<tr class=\"content\">
        <td>". $od_qty . " x " . $pd_name ."</td>
        <td align=\"right\">". displayAmount($pd_price). "</td>
        <td align=\"right\">". displayAmount($od_qty * $pd_price). "</td>
    </tr>";
}
echo "</table>";


or like this :

Code: Select all
for ($i = 0; $i < $numItem; $i++) {
   extract($orderedItem[$i]);
   $subTotal += $pd_price * $od_qty;
myVar="<tr class=\"content\">
        <td>". $od_qty . " x " . $pd_name ."</td>
        <td align=\"right\">". displayAmount($pd_price). "</td>
        <td align=\"right\">". displayAmount($od_qty * $pd_price). "</td>
    </tr>";
}
$myVar=$myVar."</table>";
User avatar
gandahar
New php-forum User
New php-forum User
 
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.