Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Everything posted by margaux

  1. Hi HartleySan, The link you provided is a good starting place to understand how to style html emails and I've read something similar in the past. To send an html email so the html tags are interpreted as opposed to displaying as literals, one needs to send the email via an email client, such as Thunderbird. So I think I need to speak to my hosting provider to see if/how they support this functionality. Other options are MailChimp and Campaign Monitor, but I need to find a way to automate the process. I've googled this loads and it comes up with lots of helpful links for styling html emails but not the next step of actually getting the html tags to be recognised as html tags and not literal text. Just thought I'd post this in case it helps anyone else. Thanks again for replying! UPDATE: my hosting provider told me to include the appropriate headers in the mail function so all is good. $to = 'info@example.com'; $subject = 'example'; $message = 'ipsem lorem etc.'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail ($to, $subject, $message, $headers);
  2. The goal is to take data from a form and generate costs using some fairly complicated formula and the form data. Then present a table of results on screen and email the table to the user. So I took your suggestion <?php $content = '<table id="data_table"><thead><tr><td></td>'; setlocale(LC_MONETARY, 'en_GB'); foreach ($qty_array as $qty){ echo '<td align="center">' . $qty . '</td>'; } echo '</tr></thead>' ."\r\n"; $content .= '</tr></thead>' ."\r\n"; foreach ($awd_total_multiple as $row=>$awd_multiple) { echo '<tr><td>' . $row . '</td>'; foreach ($qty_array as $qty) { $qty = ($qty == 1) ? 2 : $qty; $subtotal = get_awd_subtotal($qty, $total_components_per_circuit, $num_circuit_components); // calculate cost adder per BGA QFN placement $total_BGAs = get_total_BGAs($qty,$num_BGA_circuit); $cost_adder = get_cost_adder($qty,$total_BGAs); //calculate total $awd_total = $subtotal + $cost_adder; //calculate working days to do $working_days = get_working_days($qty, $total_components_per_circuit, $total_BGAs); $total_multiplier = ($working_days < number_format($row)) ? $awd_multiple : 0; if ($row == 15) {$total_multiplier = 1;} $tot_to_display = ($total_multiplier == 0) ? ' ' : money_format("%= #5.0n", $awd_total * $total_multiplier); echo '<td>'. $tot_to_display . '</td>'."\r\n"; $content .= '<td>'. $tot_to_display . '</td>'; } echo '</tr>'; $content .='</tr>'; } echo '</table></div>'; $content .= '</table></div>'; email_table($em, $content); // this function sends the email And I'm nearly there! Unfortunately all the html tags were displayed as literals in the email. <table id="data_table"><thead><tr><td></td></tr></thead> <td> £ 1,788</td><td> £ 1,788</td><td> £ 2,285</td><td> £ 2,919</td><td> £ 2,886</td><td> £ 3,421</td><td> £ 3,872</td><td> £ 5,237</td><td> </td></tr><td> £ 715</td><td> £ 715</td><td> £ 914</td><td> £ 1,168</td><td> £ 1,154</td><td> £ 1,368</td><td> £ 1,549</td><td> £ 2,095</td><td> £ 3,179</td></tr><td> £ 615</td><td> £ 615</td><td> £ 786</td><td> £ 1,004</td><td> £ 993</td><td> £ 1,177</td><td> £ 1,332</td><td> £ 1,802</td><td> £ 2,734</td></tr><td> £ 476</td><td> £ 476</td><td> £ 608</td><td> £ 777</td><td> £ 768</td><td> £ 910</td><td> £ 1,030</td><td> £ 1,393</td><td> £ 2,114</td></tr><td> £ 436</td><td> £ 436</td><td> £ 558</td><td> £ 712</td><td> £ 704</td><td> £ 835</td><td> £ 945</td><td> £ 1,278</td><td> £ 1,939</td></tr><td> £ 397</td><td> £ 397</td><td> £ 507</td><td> £ 648</td><td> £ 641</td><td> £ 760</td><td> £ 860</td><td> £ 1,163</td><td> £ 1,764</td></tr><td> £ 358</td><td> £ 358</td><td> £ 457</td><td> £ 584</td><td> £ 577</td><td> £ 684</td><td> £ 774</td><td> £ 1,047</td><td> £ 1,590</td></tr></table> I'll read up on html emails to sort that one out, but I may be back The previous code I posted for the function extract_id was to try to read in the html page on which the table was displayed and grab the inner html to use as the $message for the mail() function. Not sure if that would have worked but maybe I'll try to get that working another day. Thanks again for your help.
  3. Wouldn't you just generate the HTML table using PHP, and then embed it in the email using the PHP mail function? um, isn't this what I asked in the first post, the subject of this thread? Here's the code to generate the table ( not including the pre-defined functions, of which there are at least 10). <table id="data_table"><thead><tr><td></td> <?php setlocale(LC_MONETARY, 'en_GB'); foreach ($qty_array as $qty){ echo '<td align="center">' . $qty . '</td>'; } echo '</tr></thead>' ."\r\n"; foreach ($awd_total_multiple as $row=>$awd_multiple) { echo '<tr><td>' . $row . '</td>'; foreach ($qty_array as $qty) { $qty = ($qty == 1) ? 2 : $qty; $subtotal = get_awd_subtotal($qty, $total_components_per_circuit, $num_circuit_components); // calculate cost adder per BGA QFN placement $total_BGAs = get_total_BGAs($qty,$num_BGA_circuit); $cost_adder = get_cost_adder($qty,$total_BGAs); //calculate total $awd_total = $subtotal + $cost_adder; //calculate working days to do $working_days = get_working_days($qty, $total_components_per_circuit, $total_BGAs); $total_multiplier = ($working_days < number_format($row)) ? $awd_multiple : 0; if ($row == 15) {$total_multiplier = 1;} $tot_to_display = ($total_multiplier == 0) ? ' ' : money_format("%= #5.0n", $awd_total * $total_multiplier); echo '<td>'. $tot_to_display . '</td>'."\r\n"; } echo '</tr>'; } echo '</table> Are you suggesting I assign all of the above to a variable? I had previously looked at the link you posted but I'm obviously doing something wrong as when I passed a string of a subset of the table, $content ='<table id="data_table"><thead><tr><td></td> <td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">5</td><td align="center">10</td><td align="center">20</td><td align="center">30</td><td align="center">50</td><td align="center">100</td></tr></thead> <tr><td>2</td><td> £ 1,788</td> <td> £ 1,788</td> <td> £ 2,285</td> <td> £ 2,919</td> <td> £ 2,886</td> <td> £ 3,421</td> <td> £ 3,872</td> <td> £ 5,237</td> <td> </td> </tr> </tr></table>'; I got these errors Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/circuit/test_ceil.php on line 23 Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/circuit/test_ceil.php on line 24 I appreciate you're taking the time to look at this and I have a feeling that I may be overcomplicating things but I don't know how to get the html to pass to mail().
  4. Thanks HartleySan for the reply but the link does not address what I'm trying to do. The table is generated via some server side processing using input from a form and involves some nested loops, so to generate that table within an HTML email is not possible. I amended the first function as follows. function extract_id($url, $id) { $content = file_get_contents($url); $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'); $dom= new DOMDocument(); $dom->loadHTML($content); $dom->preserveWhiteSpace = false; $element = $dom->getElementById($id); $innerHTML = innerHTML($element); return($innerHTML); } but got a bunch of warnings, here are just a few. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: misplaced <head> tag in Entity, line: 4 in /Applications/MAMP/htdocs/circuit/get_circuit_cost.php on line 25 Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 51 in /Applications/MAMP/htdocs/circuit/get_circuit_cost.php on line 25 Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: invalid element name in Entity, line: 59 in /Applications/MAMP/htdocs/circuit/get_circuit_cost.php on line 25 Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 75 in /Applications/MAMP/htdocs/circuit/get_circuit_cost.php on line 25 Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 75 in /Applications/MAMP/htdocs/circuit/get_circuit_cost.php on line 25 Not sure if this is even the way to go about getting the table in the email.Any other suggestions?
  5. I've generated a table of data using form data and the table needs to be emailed. How do you insert a php generated table into an email? I have a feeling that this could be achieved using javascript but I've never got comfortable with js so if it could be done with php, I would prefer to go that route. If you go to this link and fill in the form, you'll see the resulting table that needs to be included in an email. (There is validation on the form but if you input invalid data, you'll just get a blank screen as I'm working on the core functionality at the moment. ) I found these functions online function extract_id($content, $id) { // use mb_string if available if (function_exists('mb_convert_encoding')) { $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'); } $dom= new DOMDocument(); $dom->loadHTML($content); $dom->preserveWhiteSpace = false; $element = $dom->getElementById($id); $innerHTML = innerHTML($element); return($innerHTML); } /** * Helper, returns the innerHTML of an element * * @param object DOMElement * * @return string one element's HTML content */ function innerHTML($contentdiv) { $r = ''; $elements = $contentdiv->childNodes; //line 77 foreach( $elements as $element ) { // line 78 if ( $element->nodeType == XML_TEXT_NODE ) { $text = $element->nodeValue; // IIRC the next line was for working around a // WordPress bug //$text = str_replace( '<', '<', $text ); $r .= $text; } // FIXME we should return comments as well elseif ( $element->nodeType == XML_COMMENT_NODE ) { $r .= ''; } else { $r .= '<'; $r .= $element->nodeName; if ( $element->hasAttributes() ) { $attributes = $element->attributes; foreach ( $attributes as $attribute ) $r .= " {$attribute->nodeName}='{$attribute->nodeValue}'" ; } $r .= '>'; $r .= innerHTML( $element ); $r .= "</{$element->nodeName}>"; } } return $r; } When I tried using them, I received these error messages, but I am uncertain what to pass as the argument. Would appreciate any help, thanks. Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/circuit/circuit.inc.php on line 77 Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/circuit/circuit.inc.php on line 78
  6. I can understand that you would want to move on, but there is something in your data or code that php doesn't like because it would not arbitrarily miss out the last element. Maybe its ok for coursework but it wouldn't be in a live situation. I'm guessing there's a random 'unprintable' character in your code that is throwing things off. Good luck with the rest of your course.
  7. I would think it is down to how your data is being stored or passed around. As HarleySan suggested, sprinkle your code with var_dump or print_r to see how the data is affected by your manipulations. It would be helpful if you posted the results of the dumps so we can see what might be causing the problem. Also I'm surprised that your code worked before changing the '\t' to "'t" as the first will be interpreted literally and the second as a tab character.
  8. The only requirement for a web page is HTML markup. It may not look great or do fun things but it is the language to display things on a web page. CSS is used for styling - to dictate how the page will look - the colours, layout, fonts etc. Javascript is used to provide behavioural features such as sliders, rotators, drop down menus; though with clever use of CSS you can actually provide some of these features without javascript. PHP and MySQL make the page dynamic by manipulating stored data and responding to user driven events such as submitting a form. But none of these will display a web page. There are a number of online tutorial sites you can try - lynda.com, htmldog, codeacademy are a couple and there are some good resources on this page. Below is a table based layout. For the pagination, you will need to keep track of the rows as well. There is an example in Larry's PHP and MySQL book that you can refer to. <?php $location = 1; $num_per_row = 3; echo '<table>'; echo '<tr>'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { // Fetch each item. if ($location == $num_per_row) { // Close the previous row, start a new one, reset the counter: echo '</tr><tr>'; $location = 1; } // Print the item within some HTML: echo '<td><h3>' . $row['category'] . ' </h3> <p><img alt="' . $row['category'] . '" src="/products/' . $row['image'] . '" />' . $row['description'] . '<br /> <a href="/browse/' . $type . '/' . urlencode($row['category']) . '/' . $row['id'] . '" class="h4">View All ' . $row['category'] . ' Products</a></p> </td>'; // Increment the counter: $location++; } // Complete the last row with empty cells, just in case: for ( $location < $num_per_row; $location++) { echo '<td> </td>'; } } ?>
  9. You don't need php for this. An anchor tag with the href attribute set to the facebook page url is all that is required.
  10. Your problem is down to your markup. The above code is outputting each row of data as list items which by default are block items. It appears that you don't have an understanding of HTML as you are not using the table based layout you have started. You may not be getting php errors but you will certainly get display errors as you haven't started and ended your list. There are a number of ways to rectify your current situation e.g. open and close your list and use css to style the list items as inline. The easiest solution though not necessarily the best is to replace the list tags with table data tags.
  11. Off the top of my head you have php tags within php tags in the value attribute which will just be printed instead of interpreted. Also you're using single quotes which displays everything literally. There are different ways to use quotes when using php to display html. Use double quotes and escape the double quotes for the attributes; or if using single quotes, end the single quotes for variables and php code and use the concatenate operator. My preferred way is to come out of php altogether when displaying lots of html markup. Here's one option if($loggedin) { print '<p>You are now logged in!</p>'; } else { ?> // exit php <h2>Login Form</h2> <form action="login.php" method="post"> <p><label>Email Address <input type="text" name="email" value="<?php if(isset($_POST['email'])){ print htmlspecialchars($_POST['email']); }?>"/></label></p> <p><label>Password <input type="password" name="password" /></label></p> <p><input type="submit" name="submit" value="Log In!" /></p> </form> <?php // start php again } ?>
  12. I would think you are eminently hireable (if that is even a word:)) Here's a little bit of my experience for what it is worth, though I am looking for freelance work and not a regular position. There are loads of opportunities out there and also a lot of competition. You will need to be able to show prospective clients/employers what you are capable of very quickly. So you need an online portfolio/website that you can refer people to. Get yourself on LinkedIn if you're not already and get testimonials from people in the industry - maybe Larry would write one for you. Consider online agencies like people per hour and elance. I'll warn you now, most of the stuff on there is not worth your time but if you are prepared to sift through the many offerings you will find a few worth pursuing. I've created a filter that only sends me jobs that meet certain criteria. I did get one which then provided 5 referrals 3 of which converted. Good luck.
  13. Thanks HartleySan - that's a very nice solution to what I was trying to do. I appreciate you taking the time to explain it as I understand the preg functions better now. I misunderstood the manual and was thinking that the 3rd argument was an array collecting all the matches, but its for collecting full and partial matches.
  14. No need to apologise but do please start a new topic for each question unless directly related. This is so people with similar questions can search and find relevant answers e.g. What does tinymce have to do with Registration? Also you should have a look at the forum guidelines if you haven't already. There's a link to them bottom right of the page. One more thing - are you sure you have the right level of experience for this book? It does assume an intermediate knowledge of programming and php and expects you to be able to solve the questions you're asking. You might want to have a look at PHP and MySQL for Dynamic Websites.
  15. get_password_hash() is a user defined function. You should have defined it in a functions file or a config file and be sure to include the relevant file before you call it.
  16. I'm having a little trouble with preg_replace. The aim is to take a shortcode and replace it with some html code. The shortcode is of the format [image file=name.ext]. Each instance of the shortcode in some content should be replaced with <img src="path/to/images/name.ext" alt="name image" /> What is actually happening is the shortcode is being replaced with [<img src="path/to/images/name.ext" alt="name image" />] Printing out the relevant array shows no brackets so not sure where to look to solve this. Also can preg_match be used to find more than one occurrence of a pattern? The php manual indicates yes, but my testing was only coming up with one occurrence so I've resorted to using preg_match_all. Here's my test file with some content if you want to test it out. As ever please suggest any improvements. Thanks. define ('BASE_URL', '/path/to/root/'); $content = '<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> [image file=file1.jpg]<h3>Ipsem</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> [image file=file2.jpg]<h3>Lorem</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. </span>ipsem lorem blah di blah.</span>'; $html_content=replace_shortcodes($content); echo( $html_content); function replace_shortcodes($content){ $html_array=array(); $shortcodes = get_all_shortcodes($content); foreach ($shortcodes as $shortcode) { $filename = get_sc_attr($shortcode); $alt = substr($filename, 0, strpos($filename,'.')); $html_array[]='<img src="' . BASE_URL . 'images/' . $filename . '" alt="'. $alt. ' image" />'; } $html_content= preg_replace($shortcodes, $html_array, $content); return $html_content; } function get_all_shortcodes($content){ $sc_regex = '/\[\s*image\s+file\s*=\s*[\w-]+\.[\w-]+\s*\]/'; preg_match_all($sc_regex, $content, $matches); return $matches[0]; } function get_sc_attr($shortcode) { $length = (strpos($shortcode,']') - strpos($shortcode,'=')); $filename = trim(substr($shortcode, strpos($shortcode,'=') +1,$length-1)); return $filename; }
  17. Superfish is an implementation of a jquery plugin for dropdown menus that Larry implements in the coffee project in the ecom book. It makes use of another jquery plugin hoverintent to make for a nice user experience. Nothing to do with php. xto - the book you refer to is very good, you'll learn loads of different programming strategies and techniques. I'd actually recommend reading it in order which is not what I did initially. Practically every chapter introduces you to new php functions which you will find very useful.
  18. http://www.youtube.c...v=whytAReStUQ#! I love this film! xto - I couldn't get the superfish menu to work out of the box either and had to make some changes to the css. Seriously, post this question in a new thread. Also maybe it should go in a different forum,(javascript or other) as the root cause is probably to do with the javascript or the css.
  19. Hey xto, I'm going to try to say this in the nicest way possible - You're in danger of trying people's patience not because you ask questions, we like questions, but because you ask questions in a way that doesn't provide the information needed to try to answer them. 1. please read the forum guidelines - Look for the little grey text bottom right of most pages, labelled Guidelines 2. please post only RELEVANT code and error messages within code tags. We don't need to see the entire output from your error message. It's actually distracting. Use code tags which are on the edit bar and they look like <> 3. post the relevant CODE, you keep posting the error message but not any code. 4. You should start a new thread for each new question. One reason for doing so is that other people with the same question can search and find your thread. If your question is part of another thread, it won't be found and won't help others. 5. You're asking questions that you should be able to solve 1 because the level of experience for this book expects you know some basic debugging strategies and 2. with a little bit of online searching you would get some pointers as to where to look for the cause of your error. I really shouldn't answer your question given the above but ... somewhere in your code you are referencing an array value using 'sale_price' as the index, which doesn't exist. I'm going to hazard a guess that you have a line that includes $row['sale_price']. From the error dump you posted, you will see there is no index 'sale_price' but there is one named 'price'. Given what info you've provided that's all I can help with. If this doesn't help solve the problem, start a new thread and post the code that is causing the error
  20. Hey HartleySan - that is perfect! Just to confirm my understanding \] = 1) A single [ \s* = 2) Any number of (or maybe zero) whitespace characters before the literal "image" image = 3) The literal "image" \s+ = 4) One or more whitespace characters between "image" and "file" file = 5) The literal "file" \s* = 6) Any number of (or maybe zero) whitespace characters before = = = 7) the literal "=" \s* = 8) Any number of (or maybe zero) whitespace characters after = [\w-]+ = 9) One or more of any number, letter, dash or underscore (You said "character", but that might be a bit too broad.) \. = 10) A literal . (must be escaped) [\w-]+ = 11) One or more of any number, letter, dash or underscore \s* = 12) Zero or more whitespace characters \] = 13) A single ] ^ = start of string $ = end of string so anything after the ] will not be processed. the whole expression must be between backslashes I was using + to indicate something totally different! Also I thought it was necessary to enclose each part or subpattern in parantheses but I guess that is not the case. When would you use parantheses. Thanks again,you have really helped my understanding of how to build regular expressions.
  21. I need a regular expression for this shortcode [image file=name.ext] The shortcode is image and there will only be one attribute, file. Obviously there might be spaces either side of the equals sign and the name and ext can be a variable length made up of numbers, characters, dashes and underscores. Initially to keep it simple I only allowed numbers and letters in the name and ext and no spaces either side of the equals sign. I've tried several options but none are working. How do you represent the [ and ] in a regex. My attempts at escaping them with a double backslash haven't worked. Here's what I tried /^(//[image file=])+([\w.])+(\\]{1})$ I also tried using a single backslash to escape the brackets, but that didn't work either. Thanks for any suggestions.
  22. There are a number of PHP Conferences around the states, best to google for specific locations, dates etc. I haven't been to any, some tend to be expensive but I would be interested to hear your feedback if you do get to one. The other suggestion is to look up Meetups for your specific interest - there are now thousands and bound to be some local to where you will be.
  23. You could make the incoming $_POST variable into an array earlier in the logic. $words_Array = explode (' ', $_POST['words']); $count1 = count($words_Array); if ($count1 < 5) { print "<p>Please enter at least 5 words.</p>"; $flag= false; } foreach ($words_Array as $word) { if (is_numeric($word)) { print "<p>Please do not enter any numbers.</p>"; $flag= false; } } //sort the words alphabetically if ($flag) { sort($words_Array); print "<p>An alphabetized version of your list is: "; foreach ($words_Array as $word) { print "<br />\n $word "; } print "</p>"; }
  24. Well I am happy to help but you have to help us help you. Presented with this problem and given that you've already experienced a problem with a database being incorrectly pointed to, it is clear that your first trouble shooting approach should be to look at how you are pointing to the location of the images. If my site is not displaying correctly, I often look at the source code. Find the code that links to the image and click on on the link - you'll probably get a message indicating that the file does not exist. Check the folder for its existence - if you're sure there are no errors in the filename, then change the file path. Learning strategies to debug saves you loads of time.
  25. [error] => PROCEDURE ecommerce1.select_sale_items does not exist The original post indicates that the stored procedure does not exist. Are you sure you have it associated with the correct database? Try testing it in phpmyadmin with CALL select_sale_items(true) and CALL select_sale_items(false). If you dont have phpmyadmin, create a simple script which calls the stored procedure and echos out the data that will be returned. This book is really for more intermediate programmers so you might want to refer to PHP and MySQL for Dynamic Websites - it includes a chapter that covers debugging techniques.
×
×
  • Create New...