www.webdeveloper.com
Results 1 to 13 of 13

Thread: Sendmail

  1. #1
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    Question Sendmail

    I would like to be able to send a html file as the message part, using sendmail. Is this possible?

    open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
    print MAIL "To: $email\n";
    print MAIL "From: $fromsender\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "Message: $htmlfile\n";
    close (MAIL);

    $mailprog $email $fromsender $subject and $htmlfile are defined in the first section of the script.

    I could put the html code in the script but would rather have to change the html file than the cgi script.

    DAnny

  2. #2
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    First thing is you'll have to print to MAIL Content-Type: text/html as part of the header, meaning before the first blank line (\n\n). Second, it just sounds like you want a template?

    -- template.html --
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en-us">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <title></title>
    </head>

    <body>

    <!-- %CONTENT% -->

    </body>

    </html>


    -- script.pl --
    my $html_start;
    my $html_end;
    { &nbsp; undef local $/;
    &nbsp; &nbsp; open TEMPL, 'template.html' or die $!;
    &nbsp; &nbsp; flock TEMPL, LOCK_SH;
    &nbsp; &nbsp; ($html_start, $html_end) = split /<!-- %CONTENT% -->/, <TEMPL>, 2;
    &nbsp; &nbsp; close TEMPL;
    }

    # ...

    print MAIL $html_start, "Message: $html", $html_end;

  3. #3
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    Question Sendmail

    I'm not a pro at this and have never used "my" for anything before. I got lost when you used ($html_start, $html_end) = Split /<!-- %CONTENT% -->/, <TEMPL>, 2;

    Why do I have to split anything? If I split the CONTENT out then how do I send the CONTENT to Sendmail?

    Danny

  4. #4
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    The split divides the template up into two pieces: everything before <!-- %CONTENT% --> is assigned to $html_start, and everything after it is assigned to $html_end. This gives you a sort of HTML header and footer to surround your content making it a complete and valid page.

    The my declares a variable to local (lexically) to the enclosing block. When using strict in your program, which is highly recommend to the point of almost being a rule, you must declare any variable you use, which is a good idea to do anyway.

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    Unhappy Sendmail

    I follow along. I tried the code that you sent and the e-mail gets sent. The only problem is I get the code of the html page in the e-mail and not the displayed page.

    I want this to work as a autoresponder. I get e-mails all the time that have pictures and background colors. This is what I'm trying to accomplish.

    Danny

  6. #6
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    Did you make sure to print the text/html Content-Type header? Can we see what you have now?

  7. #7
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    sendmail

    This is the current version that I'm working with. I tried the other and couldn't get it to work. I missing something and don't know what it is.
    I really don't what to use a template for this operation. I'm trying to send html code to show my advertizement.

    Script in the program right now. I used this just to see if I could get it to work and it doesn't.

    open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
    print MAIL "To: $email\n";
    print MAIL "From: $fromsender\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "Mime-Version: 1.0\n";
    print MAIL "Content-type: text/html\n\n";
    print MAIL "\n\n";
    print MAIL "<b>Hello,</b><br>\n";
    print MAIL "<i>This is a test to see if this works</i>\n";
    print MAIL "\n\n";
    close (MAIL);

    Danny

  8. #8
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    You have a blank line, and thus the ending of your header, after the subject. There should be only one new line there so the mime-version and content-type are included in the header.

  9. #9
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    Question sendmail

    My latest attemp didn't work. I keep getting the code in the e-mail.

    I went back to what you showed me earlier.

    my $html_start;
    my $html_end;
    { undef local $/;
    open (TEMPL, "$message") || die "Can't Open $message: $!\n";
    flock (TEMPL, LOCK_SH);
    ($html_start, $html_end) = split /<!-- %CONTENT% -->/, <TEMPL>, 2;
    close (TEMPL);
    }
    ################
    if ($mail eq'1'){
    open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
    print MAIL "To: $email\n";
    print MAIL "From: $fromsender\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL $html_start, "Message: $message1", $html_end;
    }
    close (MAIL);

    $mail is set to 1 earlier in the script. I have attached the script for your viewing. I'm using featureprice.com for my hosting. Could there be something wrong with sendmail?

    I'm going crasy trying to figure this out.

    Danny

    Attached Files Attached Files

  10. #10
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    print MAIL "To: $email\n";
    print MAIL "From: $fromsender\n";
    print MAIL "Subject: $subject\n";
    print MAIL "Content-Type: text/html\n\n";
    print MAIL $html_start, "Message: $message1", $html_end;

  11. #11
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    Question sendmail

    Did that. Still does not work. I still get the code.

    if ($mail eq'1'){
    open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
    print MAIL "To: $email\n";
    print MAIL "From: $fromsender\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "Content-Type: text/html\n\n";
    print MAIL $html_start, "Message: $message1", $html_end;
    }
    close (MAIL);

    Danny

  12. #12
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    Lose the blank line after the subject.

  13. #13
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    20

    Smile sendmail

    It works! It works! It WORKS!!!!!!!!

    Thanks more than you can imagine.

    Danny

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles