Re: email output using HTML format.
by jeffa (Bishop) on May 09, 2005 at 18:50 UTC
|
This will probably scare you, but i'd rather show someone the right way than the
"just get it done" way. You don't have to use HTML::Template, you can still
use your $myInfo variable, but do consider using MIME::Lite.
use strict;
use warnings;
use MIME::Lite;
use HTML::Template;
my $t = HTML::Template->new(filehandle => \*DATA);
$t->param(
field => 'foo',
data => 'bar',
);
my $msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Subject =>'Hello HTML',
Data => $t->output, # you can just use $myInfo here instead
Type =>'text/html',
);
$msg->send;
__DATA__
<html>
<body>
<h1>Hello HTML!</h1>
<table>
<tr>
<td><tmpl_var field></td>
<td><tmpl_var data></td>
</tr>
</table>
</body>
</html>
| [reply] [d/l] [select] |
|
|
$msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Type => 'multipart/alternative',
);
$msg->attach(
Type => 'text/html',
Data => $html,
);
$msg->attach(
Type => 'text/plain',
Data => $text,
);
The content type of 'multipart/alternative' tells the browser it can choose between the two formats as they should contain the same information. It means a bit more work for you as you have to format a text version and an HTML version, but it will make your users happy.
- Cees | [reply] [d/l] |
|
|
| [reply] |
Re: email output using HTML format.
by merlyn (Sage) on May 09, 2005 at 20:23 UTC
|
Just be sure you keep this kind of crap to yourself safely on your own disk, and don't think you can start sending it to others, especially people like me. See my rant on the subject.
| [reply] |
|
|
| [reply] |
|
|
then that'll be the best method to format the email.
No, that'd be your opinion about the best format to send the email.
My opinion is that you should set up an RSS feed to announce when
you have specials. Or maybe send me a text message that says
"You might want to visit this month's specials at http://....".
Not HTML. HTML has no place in email.
| [reply] |
|
|
|
|
"...to keep everybody happy."
Nope!
All that extra html code has to get sucked thru the little bitty copper wire before I can see the text version. Please don't burden the bandwidth challenged with redundant and unwanted html email.
...and that's ignoring, for the moment, the myriad ways html content can be used for mischief.
| [reply] |
Re: email output using HTML format.
by moot (Chaplain) on May 09, 2005 at 18:36 UTC
|
You need a mail header for Content-type probably set to text/html, or preferably include your html along with plain text in a multi-part message. This tells the receiving MUA to render the mail in the most appropriate local format. For now something like the following might work:
Content-type: text/html
printed in the header section of your email. You will also want to throw an encoding in there. | [reply] [d/l] |
|
|
It now works but please explain or give an example of throwing an encoding in there.
| [reply] |
|
|
print "Content-Type: text/html; charset=UTF-8\n"
And substitute UTF-8 for the encoding you want
| [reply] [d/l] |
Re: email output using HTML format.
by techra (Pilgrim) on May 09, 2005 at 19:24 UTC
|
By far the easiest perl module I've found to perform HTML emails is Mail::SendEasy -- a very easy interface to developing these, that has made the process incredibly simple. | [reply] |
Re: email output using HTML format.
by Animator (Hermit) on May 09, 2005 at 18:33 UTC
|
A good start would be to add something like 'Content-Type: text/html' right after the subject line (without the quotes ) | [reply] |