how to send html email from perl

Discussion in 'Perl Misc' started by Eric Osman, Jun 27, 2003.

  1. Eric Osman

    Eric Osman Guest

    I just had the same question, and found that the following works.

    If you're using the "sendmail" package (see
    http://ls6-www.cs.uni-dortmund.de/c...|CPAN|wait|/services/www-db/WAIT/DB/cpan|4120
    )

    Here's an example of sending an html message. NOTE: To actually use
    this example, you will need to change the following things:

    1) The first two lines might need to be swapped or otherwise modified
    according to what your web server and perl require at the beginning of
    perl scripts.
    2) The "to" line needs to be edited to show who you're actually sending
    the email to.
    3) The "smtp" line needs to be changed to contain an outgoing mail
    server that you are allowed to use.

    ok here's the example:

    #!perl
    #!/usr/bin/perl
    # Example of using sendmail to send html. Author: Eric Osman June 2003
    use strict;
    use CGI qw:)cgi);
    use CGI::Carp qw(fatalsToBrowser);
    use Mail::Sendmail;
    my $msg = "";
    $msg .= "here's some <b>boldface</b> to prove that html is being sent<br>";
    $msg .= "a second line<br>";
    my %mail = ( From => '',
    To => '',
    Subject => "some simple html",
    Message => "$msg",
    Smtp => 'smtp.cn.com',
    'Content-type' => 'text/html; charset="iso-8859-1"'
    );
    sendmail(%mail) || die $Mail::Sendmail::error;
    print "Content-type: text/html\n\n";
    print "your html email has been sent";

    Enjoy.

    /Eric


    > From: Mark A. Hershberger ()
    > Subject: Re: Perl, HTML to Sendmail...
    >
    > View this article only
    > Newsgroups: comp.lang.perl.misc
    > Date: 1999/09/28
    >
    > [mailed and posted]
    >
    > "Myriad" <> writes:
    >
    >> Hello, I'm looking for info on how to recode my Perl script to send HTML
    >> enabled mail via Sendmail. Can anyone help?

    >
    > (Strange, I had a user ask me the same question today. Perhaps you
    > are one and the same.)
    >
    > Find the MIME-tools package on CPAN (or, if you need a URL:
    > http://www.cpan.org/modules/by-module/MIME) and install it. In the
    > tar package, look at examples/mimesend for an example of how to send
    > html mail.
    >
    > Also, please give users the option to get plain text email instead of
    > HTML mail. HTML mail can be annoying.
    >
    > Hope that helps,
    >
    > Mark.
     
    Eric Osman, Jun 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter
    Replies:
    0
    Views:
    3,399
    Peter
    Jul 1, 2003
  2. Replies:
    2
    Views:
    431
    Tintin
    Jan 5, 2007
  3. Replies:
    13
    Views:
    525
    Randy Webb
    May 14, 2006
  4. pbd22
    Replies:
    1
    Views:
    167
  5. Replies:
    2
    Views:
    96
    Richard Balbat
    Nov 12, 2013
Loading...

Share This Page