HTML Emails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John smith

    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(fatalsToBrow ser);
    my $to='example@co m.com';
    my $from= 'example@com.co m';
    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);


  • Joe Smith

    #2
    Re: HTML Emails

    John smith wrote:[color=blue]
    > 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(fatalsToBrow ser);
    > my $to='example@co m.com';
    > my $from= 'example@com.co m';
    > 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";[/color]

    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('Tha nk you'),
    h1('Your message has been sent'),
    end_html; # This goes to browser.

    Better yet, use MIME::Lite::HTM L and post to the comp.lang.perl. misc
    newsgroup instead of this one (comp.lang.perl ).


    -Joe

    Comment

    Working...