Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

emailing php generated table

Featured Replies

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.

  • 2 weeks later...

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 :)

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.