Click to See Complete Forum and Search --> : Sendmail
Danny
01-25-2003, 08:06 PM
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:confused:
jeffmott
01-25-2003, 09:22 PM
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;
{ undef local $/;
open TEMPL, 'template.html' or die $!;
flock TEMPL, LOCK_SH;
($html_start, $html_end) = split /<!-- %CONTENT% -->/, <TEMPL>, 2;
close TEMPL;
}
# ...
print MAIL $html_start, "Message: $html", $html_end;
Danny
01-26-2003, 12:48 AM
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 :confused:
jeffmott
01-26-2003, 11:11 AM
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.
Danny
01-26-2003, 04:05 PM
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
jeffmott
01-26-2003, 06:44 PM
Did you make sure to print the text/html Content-Type header? Can we see what you have now?
Danny
01-27-2003, 12:13 AM
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 :confused:
jeffmott
01-27-2003, 06:42 AM
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.
Danny
01-27-2003, 10:13 AM
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
:confused:
jeffmott
01-27-2003, 12:37 PM
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;
Danny
01-27-2003, 01:57 PM
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 :confused:
jeffmott
01-27-2003, 03:02 PM
Lose the blank line after the subject.
Danny
01-27-2003, 03:05 PM
It works! It works! It WORKS!!!!!!!!
Thanks more than you can imagine.
Danny:D :D :D :D