用sendmail傳送HTML格式的郵件(轉)

post0發表於2007-08-10
用sendmail傳送HTML格式的郵件(轉)[@more@]

先將來自HTML頁面的資料解碼,再呼叫unix系統sendmail命令即可。

例如下:#!/usr/local/bin/perl

#

&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(/&/,$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=~/<!--#exec/) {

print "Content-type: text/htmlnnNo SSI permitted";

exit;

};

};

};

#E-MAIL SUBROUTINE

#ADD "&email(to,from,subject,text)" TO YOUR SCRIPT

#REMEMBER TO BACKSLASH THE @ WHEN YOU ARE NOT USING IT IN AN ARRAY

#FOR EXAMPLE:

# $to='robyoung@mediaone.net';

# $from='foo@company.com';

# $subject='Thank you for your inquiry';

# $text='Dear readernnThank you for your recent inquiry.';

# &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);

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8225414/viewspace-942995/,如需轉載,請註明出處,否則將追究法律責任。

相關文章