Agreaves Posted September 11, 2012 Share Posted September 11, 2012 In my code below whenever smarty fetches the template file it doesnt pass the values to the variables upon sending the email, but if i display it on the webpage it works perfectly. what am i not doing or doing wrong? if(isset($_POST['send'])) { $smarty->assign('row',$data); $name = $_POST['name']; $address = $_POST['address1']; $address2 = $_POST['address2']; $telephone = $_POST['telephone']; $email = $_POST['email']; $to = 'Andrew Greaves <a_greaves@live.com>'; $subject = 'Invoice'; $headers = array( "From: $name <$email>",'MIME-Version: 1.0','Content-type: text/html; charset=ISO-8859-1'); $smarty->assign('name',$name); $smarty->assign('address',$address); $smarty->assign('address2',$address2); $smarty->assign('telephone',$telephone); $body = $smarty->fetch('email_body.html'); mail($to, $subject, $body, implode("\r\n",$headers)); $message = '<p><b>Your invoice was sent successfully</b></p>'; } Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/ Share on other sites More sharing options...
Jessica Posted September 12, 2012 Share Posted September 12, 2012 1. Is the file actually called .html, or is it .tpl? 2. Can you post the template please? Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377153 Share on other sites More sharing options...
Agreaves Posted September 12, 2012 Author Share Posted September 12, 2012 Its called .tpl, the table is displayed in the email but empty, not even the pictures show up and the background images I set in the table. <html> <style type="text/css"> #title { width: 400px; font-family: Verdana; font-size: 14px; font-weight: bold; color: #000; text-decoration: underline; } #hdg_bkgrnd { background-image: url(../../images/tbl_bkgrd.jpg); } #pic_bdr { border: 1px solid #CCC; vertical-align: middle; text-align: center; width: 950px; display: table; } .details_box { display: table-cell; text-align: center; vertical-aign: middle; position: relative; padding: 0px; border: 1px solid #CCCCCC; border-radius: 5px; background-image: url(../../images/tbl_bkgrd.jpg); } #total { font-family: Verdana; font-size: 12px; font-weight: bold; color: #000; } .main_bdr { border: 0.5px solid #CCCCCC; } #cols_bkgrnd { background-color: #E5E5E5; background-image: url(../images/row_bkgrnd.jpg); } #grnd_total { font-size: 14px; font-weight: bold; color: #F00; text-decoration: underline; } </style> <body> <table width="950" border="0"> Â <tr> Â Â <td width="171" height="40" align="center" class="details_box"><strong>BILL TO</strong></td> Â Â <td width="424">Â </td> Â Â <td width="82">Â </td> Â Â <td width="82">Â </td> Â Â <td width="34">Â </td> Â Â <td width="171" height="40" class="details_box"><strong>INVOICE</strong></td> Â </tr> Â <tr> Â Â <td align="left">Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td align="center">{$date}</td> Â </tr> Â <tr> Â Â <td align="left">Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â </tr> Â <tr> Â Â <td align="left">Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â </tr> Â <tr> Â Â <td align="left">Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â </tr> Â <tr> Â Â <td align="left">Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â </tr> Â <tr> Â Â <td align="left">Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â Â <td>Â </td> Â </tr> </table> <table width="950" border="0" align="center" id="pic_bdr"> Â <tr id="hdg_bkgrnd"> Â Â <td width="160" align="center" height="40"><strong>Thumbnail</strong></td> Â Â <td width="160" align="center" height="40"><strong>Id</strong></td> Â Â <td width="160" align="center" height="40"><strong>Name</strong></td> Â Â <td width="160" align="center" height="40"><strong>Quantity</strong></td> Â Â <td width="160" align="center" height="40"><strong>Price</strong></td> Â Â <td width="160" align="center" height="40"><strong>Amount</strong></td> Â </tr> Â {foreach from=$row item=item key=key} Â <tr height="55">Â Â Â <td width="160" align="center" ><img name="" src="{$item.Thumbnail}" alt=""></td> Â Â <td width="160" align="center" id="cols_bkgrnd">#{$item.Id}</td> Â Â <td width="160" align="center" id="cols_bkgrnd">{$item.Name}</td> Â Â <td width="160" align="center" id="cols_bkgrnd">{$item.quantity}</td> Â Â <td width="160" align="center" id="cols_bkgrnd">${$item.Price}</td> Â Â <td width="160" align="center" id="cols_bkgrnd">${$item.amount}</td> Â </tr> Â {/foreach} Â <tr height="40" id="hdg_bkgrnd"> Â Â <td align="center" >Â </td> Â Â <td align="center" id="cols_bkgrnd2">Â </td> Â Â <td align="center" id="cols_bkgrnd2">Â </td> Â Â <td align="center" id="cols_bkgrnd2">Â </td> Â Â <td align="right" id="cols_bkgrnd2"><strong id="total">TOTAL</strong></td> Â Â <td align="center" id="cols_bkgrnd2"><strong id="grnd_total">${$item.total}</strong></td> Â </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377452 Share on other sites More sharing options...
Agreaves Posted September 12, 2012 Author Share Posted September 12, 2012 I had already changed it to tpl in the code, so disregard the .html. Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377453 Share on other sites More sharing options...
Agreaves Posted September 12, 2012 Author Share Posted September 12, 2012 I did a test by sending the fetched template upon compiling it and the information showed in the email except the picture, but once I use post from the form it erases all the session variables before sending the email leaving me with a blank table. Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377456 Share on other sites More sharing options...
PFMaBiSmAd Posted September 12, 2012 Share Posted September 12, 2012 but once I use post from the form it erases all the session variables  What form? What session variables?  We cannot help you with tail-end symptoms without having all the code that reproduces those symptoms. There can be a half-dozen different things your code could be doing that could cause any one symptom, but without seeing all the relevant code, it is not possible to narrow them down to the one thing that is causing the problem. Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377462 Share on other sites More sharing options...
Agreaves Posted September 12, 2012 Author Share Posted September 12, 2012 Here is the code for the form  echo "<form method=\"post\" name=\"body\" action=\"index.php\">"; echo "<table align=\"center\" id=\"tbl_bdr\" width=\"950\" border=\"0\" cellspacing=\"0\" cellpadding=\"10\"> <tr align=\"left\"> <td align=\"left\"><b>Name:</b></td> <td><input id=\"txt_box\" type=\"text\" name=\"name\"/></td> <td align=\"left\"><b>Email:</b></td> <td><input id=\"txt_box\" type=\"text\" name=\"email\"/></td>  </tr> <tr align=\"left\"> <td align=\"left\"><b>Address:</b></td> <td><input id=\"txt_box\" type=\"text\" name=\"address1\"/></td> <td align=\"left\"><b>Address(ext):</b></td> <td><input id=\"txt_box\" type=\"text\" name=\"address2\"/></td>  </tr> <tr align=\"left\"> <td align=\"left\"><b>Telephone:</b></td> <td><input id=\"txt_box\" type=\"text\" name=\"telephone\"/></td>  </tr> </table>"; echo "<table id =\"cart_bdr\" align =\"center\" border=\"0\" width=\"950\">";//format the cart using a HTML table echo "<tr id=\"hdg_bkgrnd\" height=\"40\"><td width=\"160\" align=\"center\"><b>Thumbnail</b></td><td width=\"160\" align=\"center\"><b>Id</b></td><td width=\"160\" align=\"center\"><b>Name</b></td><td width=\"160\" align=\"center\"><b>Quantity</b></td><td width=\"160\" align=\"center\"><b>Price</b></td><td width=\"160\" align=\"center\"><b>Amount</b></td></tr>"; $total = 0; //iterate through the cart, the $product_id is the key and $quantity is the value foreach ($_SESSION['cart'] as $product_id => $quantity) {   //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection   $sql = sprintf("SELECT Id, Name, Price, Pix, Thumbnail FROM products WHERE Id = %d;", $product_id);   $result = mysqli_query($con,$sql); $row = mysqli_fetch_assoc($result); $items['quantity'] = $quantity; $Id = $row['Id']; $Name = $row['Name']; $Price = $row['Price']; $Pix = $row['Pix']; $Thumbnail = $row['Thumbnail']; $amount['amount'] = number_format($quantity*$Price,2);   $line_cost = number_format( $Price * $quantity,2); //work out the line cost $total = number_format($total + $line_cost,2); $grand_total['total'] = $total; $data[] = array_merge($row,$items,$amount,$grand_total);   echo "<tr height=\"55\">"; echo "<td align='center'><div id='thumb_bdr'><img src=\"$Thumbnail\"/></div></td>"; echo "<td align=\"center\" id=\"cols_bkgrnd\"><div name=\"id\">#$Id</div></td>";   //show this information in table cells   echo "<td align=\"center\" id=\"cols_bkgrnd\"><div id='items'>$Name</div></td>";   //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product   echo "<td align=\"center\" id=\"cols_bkgrnd\">X $quantity <a href=\"$_SERVER[php_SELF]?action=remove&id=$product_id\"><img border='0' src='../images/down_arrow.gif' width='9' height='21' alt='Descrease' /> </a><a href=\"$_SERVER[php_SELF]?action=add&id=$product_id\"><img border='0' src='../images/up_arrow.gif' width='9' height='21' alt='Increase' /></a></td>"; echo "<td align=\"center\" id=\"cols_bkgrnd\"><div id='items'>$$Price</div></td>";   echo "<td align=\"center\" id=\"cols_bkgrnd\"><div id='items'>$$line_cost</div></td>";   echo "</tr>"; } //show the total   echo "<tr id=\"hdg_bkgrnd\" height=\"40\">"; echo "<td></td>"; echo "<td></td>"; echo "<td></td>"; echo "<td></td>";   echo "<td align='right'><div><b>TOTAL</b></div></td>";   echo "<td align='center'><b id='grnd_total'>$$total</b></td>";   echo "</tr>"; echo "</table>"; // Create table to hold submit and emapty cart buttons echo "<table width=\"950\" align=\"center\">";   echo "<tr>";  echo "<td width=\"237\"></td>"; echo "<td width=\"237\"></td>"; echo "<td width=\"237\"></td>"; echo "<td width=\"237\" align=\"right\"><input id=\"submit_btn\" value=\"Send\" name=\"send\" type=\"submit\"/></td>";   echo "<td width=\"237\"><input id=\"cart_btn\" type=\"button\" value=\"Empty\" onclick=\"window.location.href='$_SERVER[php_SELF]?action=empty'\" /></td>";   echo "</tr>";   echo "</table>";   echo "<b id='ship'>SHIPPING AND HANDLING NOT INCLUDED</b>";   echo "</form>";  // Email invoice program if(isset($_POST['send'])) { $smarty->assign('row',$data); $email = $_POST['email']; $body = $smarty->fetch('email_body.tpl'); $html = $body; $crlf = "\n"; $hdrs = array(        'From'  => 'Andrew Greaves <moregal63@hotmail.com>',        'Subject' => 'Invoice'        ); $mime = new Mail_mime(array('eol' => $crlf)); $mime->setHTMLBody($html); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $mail =& Mail::factory('mail'); $mail->send('a_greaves@live.com', $hdrs, $body); } Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377467 Share on other sites More sharing options...
PFMaBiSmAd Posted September 13, 2012 Share Posted September 13, 2012 The only things I can tell from the fragments of code are - Â 1) You don't have a session_start() statement, so any $_SESSION variables won't exist outside of the page request they were set on. Â 2) If you mean that the $data array doesn't contain any data, when you use it in - $smarty->assign('row',$data);, that's because web servers are stateless and the $data array you are setting in the form code only exists on that page and for the http request for that page. Â 3) You should not be executing a query inside of a loop. You should get all the product id's at once (see array_keys) and form a mysql IN(id,id,id,....) term for the WHERE clause to get all the product information in one query.. You would then simply loop over the result set from that query to output the cart contents. As you are looping over the result from the query, you would get the quantity by using the current product_id from the row you are looping over as an index into the session cart array. Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377537 Share on other sites More sharing options...
Agreaves Posted September 13, 2012 Author Share Posted September 13, 2012 Can you give me an example of that query youre talking about for the cart contents? Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377658 Share on other sites More sharing options...
Agreaves Posted September 14, 2012 Author Share Posted September 14, 2012 Also I do have a session_start on the cart page. If I do a smarty->display the template prints to the screen. I am looking into adjusting the code for the cart to remove the query from the loop. Quote Link to comment https://forums.phpfreaks.com/topic/268270-help-with-smarty-fetch-email-program/#findComment-1377773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.