May 14, 201313 yr Is it possible to insert a php generated table into an email? My script takes input from a form, does a bunch of processing to output a table of data and the table needs to be emailed to the user who completed the form. I've been playing around with these functions but I'm not having any joy. Any ideas? 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); } function innerHTML($contentdiv) { $r = ''; $elements = $contentdiv->childNodes; foreach( $elements as $element ) { // line 46 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; } I get a bunch of warnings like these 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 Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 76 in /Applications/MAMP/htdocs/circuit/get_circuit_cost.php on line 25 var_dump on $element yields object(DOMElement)#2 (0) { } and line 46 gives an invalid argument error. Any help would be greatly appreciated.
May 29, 201313 yr Hi Gadgetgirl, I’m not sure if this has been resolved, if not could you provide me the form that is being submitted (is it dynamic?) Also is the code provided the contents of get_circuit_cost.php (just to verify)? And I’ll take a bit of a closer look
May 29, 201313 yr Author Hi CSN-UK Thanks for looking. I have resolved this via another means - as I built up the html for display, I also added it to a content variable which I then passed to php's mail function. It works nicely. If you have any comments re the above functions which I found on the internet, I would be interested to hear them as I may want to use them on a future project. I put the above code in a functions.php file. get_circuit_cost.php included functions.php and called extract_id.
Create an account or sign in to comment