用sendmail发送HTML格式的邮件

12/3/2006来源:Qmail人气:10934

先将来自HTML页面的数据解码,再调用unix系统sendmail命令即可。

例如下:

#!/usr/local/bin/perl
#
%26amp;readparse;
PRint "Content-type: text/htmlnn";
#
#********* BEGIN BODY********************

#******** END BODY************************
#
# EACH VALUE IN THE HTML FORM WILL BE CONTAINED IN
# THE THE @VALUE ARRAY.
sub readparse {
read(STDIN,$user_string,$ENV{'CONTENT_LENGTH'});
if (length($ENV{'QUERY_STRING'})>0) {$user_string=$ENV{'QUERY_STRING'}
};
$user_string =~ s/+/ /g;
@name_value_pairs = split(/%26amp;/,$user_string);
foreach $name_value_pair (@name_value_pairs) {
($keyWord,$value) = split(/=/,$name_value_pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge;
push(@value, "$value");
$user_data{$keyword} = $value;
if ($value=~/print "Content-type: text/htmlnnNo SSI permitted";
exit;
};
};
};

#E-MAIL SUBROUTINE
#ADD "%26amp;email(to,from,subject,text)" TO YOUR SCRipT
#REMEMBER TO BACKSLASH THE @ WHEN YOU ARE NOT USING IT IN AN ARRAY
#FOR EXAMPLE:
# $to='[email protected]';
# $from='[email protected]';
# $subject='Thank you for your inquiry';
# $text='Dear readernnThank you for your recent inquiry.';
# %26amp;email($to,$from,$subject,$text);

sub email {
local($to,$from,$sub,$letter) = @_;
$to=~s/@/@/;
$from=~s/@/@/;
open(MAIL, "|/usr/lib/sendmail -t") || die
"Content-type: text/textnnCan't open /usr/lib/sendmail!";
print MAIL "To: $ton";
print MAIL "From: $fromn";
print MAIL "Subject: $subn";
print MAIL "$lettern";
return close(MAIL);
} , ,