For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > January 2005 > Re: [SMARTY] sending emails using my smarty templates









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] sending emails using my smarty templates
Abdul-Wahid Paterson

2005-01-21, 8:59 pm

I will try out the DOM functions. They do look quite . 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:
>
> correct.
>
>
> correct. ;-)
>
>
> why not install PHP5 on your machine?
>
>
> 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/functi...et-contents.php
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com