tags:

views:

55

answers:

3

I am very new to writing in Perl.

I have a checkout pl which sends an email to the buyer with details of their order. How do I format in Perl to display the order in a "pretty" format such as tables, coloured background images etc like in an html page???
This is the section of code I would like to format into something more attractive:

##-----Send email confirmation to the customer-----
open (MAIL,"|$mailprogram");
print MAIL "To: $b_email\n";
print MAIL "From: $oursalesemail\n";
print MAIL "Subject: Order Confirmation\n";
print MAIL "\n\n";
print MAIL "Hi $b_first\n";
print MAIL "\n\n";
print MAIL "Your order has been received.  A summary of your order appears below.\n";
print MAIL "\n";
&printMailFieldsFromForm;
print MAIL "\n";
print MAIL "Thank-you for your order.  It will be shipped posthaste.\n\n";
close MAIL;

Cheers KD

+1  A: 

See Email::Sender, Email::Sender::Manual::QuickStart and Email::Simple.

You can use Email::MIME::CreateHTML to create the message.

The Perl Email Project web site seems a little dormant, but their mailing list is active. You can also get help there.

I have the sinking feeling that you grabbed some ancient crap full of bad practices and security holes lying around on the web and you are processing CGI submissions manually as well. Please use CGI::Simple or CGI.pm.

Sinan Ünür
I can't see anything in those Perldoc pages about how to format the email so it is "pretty" … or even anything (explict) about sending email in formats other than text/plain.
David Dorward
@David: I had forgotten the replacement for `Mime::Lite::HTML` and I was searching for it. In any case, I see you posted that while I was searching ;-) +1.
Sinan Ünür
Don't people recommend against using CGI.pm?
xenoterracide
@xenoterracide What do you mean? Who does? For what reason? I do recommend `CGI::Simple` over `CGI.pm` because it leaves out the functional interface and the HTML generation methods.
Sinan Ünür
+1  A: 

You need to construct two versions of the email. A plain text version (as you have now) and an HTML formatted version. Note that email clients have a wide range of support for web standards from very good to really poor.

Then you need to join them together into an email. I've had very good results using Email::MIME::CreateHTML in the past.

David Dorward
A: 

You should be able to do all kinds of formatting with Template::Toolkit, including emails. you might want to look into other templating engines too such as Text::Template of course if you don't need Unicode you could even consider the evil format. If you want HTML just write the html with template parts.

xenoterracide