469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

HTML Emails

I am trying to use Sendmail to send an HTML email. apart from not wotking
the folloing script returns and erro message of Premature end of script
headers
#!/usr/bin/perl
use CGI;#::Carp qw(fatalsToBrowser);
my $t**********@com.com';
my $from= 'e******@com.com';
my $subject='Using Sendmail';

open(MAIL, "|/path/sendmail -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "Content-type: text/html\n\n";
print MAIL "Hello Friend\n";
print MAIL "It has been brought to our attention that you are interested in
using the sendmail program.\n";
print MAIL "If you use the template script given here you should be sending
email from your website today.\n";
print MAIL "Thank you.\n";
print MAIL "Create a Site\n";
close(MAIL);
Aug 21 '05 #1
1 5541
John smith wrote:
I am trying to use Sendmail to send an HTML email. apart from not wotking
the folloing script returns and erro message of Premature end of script
headers
#!/usr/bin/perl
use CGI;#::Carp qw(fatalsToBrowser);
my $t**********@com.com';
my $from= 'e******@com.com';
my $subject='Using Sendmail';

open(MAIL, "|/path/sendmail -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "Content-type: text/html\n\n";


That's your problem. You need to output two different
content-type headers, one to the browser, the other to sendmail.
Use the "here-document" style instead of several print()s.

print header; # This goes to the browser
print MAIL <<"HEADER"; # This goes to sendmail
To: $to
From: $from
Subject: $subject
Content-type: text/html

HEADER
print MAIL <<"MESSAGE"; # Rest of message
your message goes here
MESSAGE
close MAIL or warn "Problems in sending mail: $!";
print start_html('Thank you'),
h1('Your message has been sent'),
end_html; # This goes to browser.

Better yet, use MIME::Lite::HTML and post to the comp.lang.perl.misc
newsgroup instead of this one (comp.lang.perl).
http://search.cpan.org/~alian/MIME-L...L-1.21/HTML.pm

-Joe
Aug 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by dan glenn | last post: by
7 posts views Thread by Tappy Tibbons | last post: by
12 posts views Thread by Dave G | last post: by
21 posts views Thread by maya | last post: by
1 post views Thread by robbiesmith79 | last post: by
2 posts views Thread by Big Moxy | last post: by
1 post views Thread by Lelu | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.