Google Answers Logo
View Question
 
Q: How to create CGI html email ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: How to create CGI html email
Category: Computers > Programming
Asked by: asuresh-ga
List Price: $20.00
Posted: 06 Nov 2002 09:29 PST
Expires: 06 Dec 2002 09:29 PST
Question ID: 100423
How to create CGI html email

Request for Question Clarification by seizer-ga on 06 Nov 2002 09:37 PST
Hi there asuresh. Could you clarify a little on exactly what task
you're trying to perform? Myself or other researchers would need a
little more detail, before being able to give you a good answer!

Clarification of Question by asuresh-ga on 06 Nov 2002 09:48 PST
How to Send HTML email using CGI script?. I can able to do it by PHP,
need help with CGI.

Request for Question Clarification by hammer-ga on 06 Nov 2002 10:00 PST
In what language are you writing your CGI script?

Clarification of Question by asuresh-ga on 06 Nov 2002 10:02 PST
The language I am using is Pearl.
Answer  
Subject: Re: How to create CGI html email
Answered By: hammer-ga on 06 Nov 2002 10:36 PST
Rated:5 out of 5 stars
 
Asuresh,

Basically, you need to add this line to the top of your email:
Content-type: text/html and send your email with HTML tags.

You have a couple of choices:

1. Here is a simple script for sending email using Perl. There is one
line in the middle which changes based on whether you are sending text
or HTML formatted email. The comments in the article describe how to
change the content type line.
http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/32/pid/219/fid/364

2. Here is a script that sends email as both text and HTML (to deal
with everyone's mail reader). It assumes that you have Mail::Sendmail
available.

#!/usr/bin/perl
use Mail::Sendmail;
use strict;

my ($boundary,$html_email,$text_email,%email);

$boundary = 'allyourbasearebelongtous' . time;

$html_email = qq(<html>
<head><title>Email</title></head>
<body>
Hello world!
</body>
</html>
);

$text_email = qq(Hello world!\n);

%email = (  To              => 'you@yours.org',
            From            => 'me@mine.org',
            Subject         => 'Hello world',
            'MIME-Version'  => 1.0,
            'Content-type'  => "multipart/alternative;
boundary=$boundary",
            Message =>
qq(--$boundary
Content-type: text/plain; charset=UNKNOWN-8BIT

$text_email
--$boundary
Content-type: text/html; charset=iso-8859-1

$html_email
--$boundary--
)
);

sendmail(%email);

I found this script in a newsgroup posting whose URL is too long to
paste in here reliably. You can find it by searching Google Groups
using:
Perl send HTML email 


3. Use the MIME::Lite module. Here is a link with tutorials and
example of sending email with different formatting and attachments,
including HTML.

About
http://perl.about.com/library/weekly/aa042302c.htm

Good luck with your script!

- Hammer

Request for Answer Clarification by asuresh-ga on 06 Nov 2002 14:07 PST
"It assumes that you have Mail::Sendmail
available." My path for Sendmail is 

"#!/usr/sbin/sendmail "

But I have diffrent path also there,

 #!/usr/local/bin/perl
require DBI;
require Mysql::Statement;
require DBD::mysql;

It is not taking Sendmail, if I give bith paths, however it is working fine if
use "#!/usr/sbin/sendmail", but require DBI;
require Mysql::Statement;
require DBD::mysql;

these command fails.

Pelase let me know, how to include both paths.

-Suresh A

Clarification of Answer by hammer-ga on 06 Nov 2002 15:05 PST
Mail::Sendmail and sendmail are not the same thing. You do not need
the path to sendmail. To use that option, you need to have
Mail::Sendmail installed.

To use regular unix sendmail:

$sendmail = '/usr/sbin/sendmail';

open(MAIL, "|$sendmail -oi -t") or die "Can't open pipe to $sendmail:
$!\n";
print MAIL "To: $recipient\n";
print MAIL "From: $sender\n"; 
print MAIL "Subject: $subject\n\n";
print MAIL "$mail_body";
close(MAIL) or die "Can't close pipe to $sendmail: $!\n";

Request for Answer Clarification by asuresh-ga on 06 Nov 2002 16:01 PST
Okay, How do you create HTML formated Eamil  using unix send mail?

Clarification of Answer by hammer-ga on 07 Nov 2002 04:29 PST
The first link I posted for you has a simple script using Unix
sendmail that does either text or HTML, depending ont he content type
you specify.

http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/32/pid/219/fid/364
asuresh-ga rated this answer:5 out of 5 stars

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy