Re: [SMARTY] sending emails using my smarty templates

From: Date: Sat, 22 Jan 2005 00:13:52 +0000
Subject: Re: [SMARTY] sending emails using my smarty templates
References: 1 2 3 4 5 6 7 8 9  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12194@lists.php.net to get a copy of this message
I will try out the DOM functions. They do look quite cool. In the meantime I found this.... http://php-html.sourceforge.net/ Which is a bit basic (not sure yet how solid or accurate it is) but does actually work on my pages that I have tested so far (which as HTML goes, are probably quite complex). I have something like this in my code now and it does work........ include_one('htmlparser.inc'); include_once('Mail.php'); include_once('Mail/mime.php'); // Create a new MIME mail object $mime = new Mail_mime(); // Create an array of email headers $hdrs = array( 'From' => 'Test <foo@bar.com>', 'Subject' => "testing our smarty" ); // fetch my page using given template $html = $smarty->fetch("mypage.tpl"); // new parser object $parser = new HtmlParser($html); // parse the page looking for <img> tags while($parser->parse()) { if(strtolower($parser->iNodeName) == strtolower('img')) { foreach($parser->iNodeAttributes as $key => $value) { if(strtolower($key) == strtolowr('src')) { // add the image $mime->addHTMLImage($key); } } } } $mime->setHTMLBody($html); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $mail =& Mail::factory('mail'); $mail->send('foo@bar.com', $hdrs, $body); I now need to do something about images in different directories e.g. /images and also put them through an array as some of my images appear mutliple times in the page and I don't want to add them to the email twice otherwise one seems to display as an attachment rather than inline. Regards, Abdul-Wahid On Fri, 21 Jan 2005 20:38:58 +0100, Jochem Maas <jochem@iamjochem.com> wrote: > Abdul-Wahid Paterson wrote: > > I had thought of using this.... > > > > > > http://uk.php.net/manual/en/function.dom-domdocument-loadhtml.php > > > > Using the new DOM functions you should be able to load the HTML and > > automatically extract all the <img> tags. The big BUT is... > > > > 1. I think it is only available in PHP5 > > correct. > > > 2. I have not tested it > > correct. ;-) > > > > > Can anyone with PHP5 installed work out (or does anyone know) if this > > why not install PHP5 on your machine? > > > would in theory work? :) > > you can definitely use the PHP5 XML/DOM extension(s) to manipulate an > bits of HTML (including doing what you want to do here) - but I bet its > quicker/easier with a regexp, a few step you would have to go to: > > 1. find every occurance of the src attribute in an image tag (in your html) > 2. for every 'src' value you find you have to download the file (maybe > its on your server already so then you don't!) > 3. attach the image to the email (lets assume you use phpmailer) giving > a 'cid' identifier (using the filename minus thew extension would be handy). > 4. replace every occurance of the src attribute in an image tag with a > 'cid' identifier - using backreferences that will be quite easy if you > have previously made the 'cid' to equal the filename minus the extension. > 5. send > > functions that would help you greatly here are preg_match_all() and > preg_replace(); for downloading the img files you may be able to use > file_get_contents(): > http://nl2.php.net/manual/en/function.file-get-contents.php > > > > > Abdul-Wahid > > > > On Fri, 21 Jan 2005 17:41:37 +0000, pete M <pmorgan@ukds.net> wrote: >

« previous php.smarty.general (#12194) next »