分享
 
 
 

cgi中的邮件发送器

王朝other·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

#!/usr/bin/perl

#以二进制模式传送附件。

binmode(STDIN);

binmode(STDOUT);

binmode(STDERR);

#sender.pm模块位置

$ProgDir="c:\\httpd\\htdocs\\cgi-bin\\clmail";

#附件目录

$AttachDir="c:\\worktemp\";

#发信按钮图像

$MailButton='http://127.0.0.1/mailimage/mail_b.JPG';

#附件按钮图像

$AttachButton='http://127.0.0.1/mailimage/attach_b.JPG';

#页面标题

$title="免费邮件";

#SMTP服务器

$SmtpSever='192.192.194.1'; #这是一个虚构的服务器,请使用你的发信服务器代替它。

#ShowAttachForm();

#sender模块位置

push(@INC,$ProgDir);

my($From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum,$AttachFile1,$AttachFile2,$AttachFile3);

use CGI;

$input=new CGI;

if($input->param('attachbutton.x') ne ""){

&ReadInput;

ShowAttachForm($From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum,$AttachFile1,$AttachFile2,$AttachFile3,0);

}

#($ENV{'QUERY_STRING'} eq 'showattach') and &ShowAttachForm;

#&ShowAttachForm;

if($input->param('showmailform') eq 'yes')

{

&ShowMailForm;

exit;

}

if($input->param('beattachfile') eq 'yes'){

&AttachFile;

exit;

}

if ( $input->param('mailbutton.x') ne '' ) {

#&ReadInput;

&SendMail;

exit;

}

&ShowMailForm;

sub print_head{

print<<"EOF";

content-type:text/html\n

<html><head><title>$title</title></head>

<body>

EOF

}

sub print_foot{

print<<"EOF";

</body>

</html>

EOF

}

############################################################################

sub ShowAttachForm #4/14/00 4:02PM

############################################################################

{

my ($From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum,$AttachFile1,$AttachFile2,$AttachFile3,$TooMany)=@_;

&print_head;

if ($TooMany eq 1) {

print<<"EOF";

<p><strong><font size="4" color="#FF0000">对不起,附件不能超过3个,本附件不能传送。</font></strong></p>

EOF

}

print<<"EOF";

<p><font size="3" color="#008000">按以下步骤发送附件:</font></p>

<form action="$ENV{'SCRIPT_NAME'}" method="post" align="center"

ENCTYPE="multipart/form-data">

<input type="hidden" name="beattachfile" value="yes"><input type="hidden" name="from"

value="$From"><input type="hidden" name="to" value="$To"><input type="hidden"

name="subject" value="$Subject"><input type="hidden" name="attachfile" value="$AttachFile"><input

type="hidden" name="cc" value="$Cc"><input type="hidden" name="bcc" value="$Bcc"><input

type="hidden" name="mailcontent" value="$MailContent"><input type="hidden"

name="attachnum" value="$AttachNum"><input type="hidden" name="attachfile1"

value="$AttachFile1"><input type="hidden" name="attachfile2" value="$AttachFile2"><input

type="hidden" name="attachfile3" value="$AttachFile3"><table border="0" cellpadding="0" cellspacing="0"

width="57%" height="76" style="font-size: 9pt; letter-spacing: 2px">

<tr>

<td width="50%" height="18">1、在以下框中点击“浏览”并在随后弹出的对话框中选择附件。</td>

</tr>

<tr>

<td width="50%" height="1"><input type="file" name="newfile" size="30"></td>

</tr>

<tr>

<td width="50%" height="18">2、点击“粘贴”键,将附件贴到邮件上。<input

type="submit" value="粘贴"></td>

</tr>

</table>

</form>

<form action="$ENV{'SCRIPT_NAME'}" method="post" align="center">

<input type="hidden" name="showmailform" value="yes"><input type="hidden" name="from"

value="$From"><input type="hidden" name="to" value="$To"><input type="hidden"

name="subject" value="$Subject"><input type="hidden" name="attachfile" value="$AttachFile"><input

type="hidden" name="cc" value="$Cc"><input type="hidden" name="bcc" value="$Bcc"><input

type="hidden" name="mailcontent" value="$MailContent"><input type="hidden"

name="attachnum" value="$AttachNum"><input type="hidden" name="attachfile1"

value="$AttachFile1"><input type="hidden" name="attachfile2" value="$AttachFile2"><input

type="hidden" name="attachfile3" value="$AttachFile3"><table

style="font-size: 9pt; letter-spacing: 2px" width="435" cellspacing="0" cellpadding="0">

<tr>

<td width="431" height="18">3、如有多个附件,重复以上步骤。</td>

</tr>

<tr>

<td width="431" height="18">4、点击“完成”,以完成附件操作。<input

type="submit" value="完成"></td>

</tr>

<tr>

<td width="431" height="18"><font size="3" color="#008000">附件列表:</font><p><select

name="fj" size="3">

<option value="AttachFile1">$AttachFile1</option>

<option value="AttachFile2">$AttachFile2</option>

<option value="AttachFile3">$AttachFile3</option>

</select></td>

</tr>

</table>

</form>

EOF

&print_foot;

exit;

} ##ShowAttachForm

############################################################################

sub ReadInput #4/14/00 2:34PM

############################################################################

{

$From= $input->param('from');

$To=$input->param('to');

$Subject=$input->param('subject');

$Cc=$input->param('cc');

$Bcc=$input->param('bcc');

$AttachFile=$input->param('attachfile');

$MailContent=$input->param('mailcontent');

$AttachNum=$input->param('attachnum');

$NewFile=$input->param('newfile');

$AttachFile1=$input->param('attachfile1');

$AttachFile2=$input->param('attachfile2');

$AttachFile3=$input->param('attachfile3');

} ##ReadInput

############################################################################

sub SendMail #4/13/00 10:14AM

############################################################################

{

&ReadInput;

#读入附件信息

if($AttachNum ne ""){ @AttachFileName=split(/;/,$AttachFile);}

use Sender;

$Send = new Sender({from=>$From,

smtp=>$SmtpSever});

if ( !( ref $Sender) =~ /Sender/i ) {

die $Sender::Error;

}

$Send->OpenMultipart({to=>$To,

subject=>$Subject,

replyaddr=>$Cc});

$Send->Body;

$Send->SendLine($MailContent);

if ($AttachNum ne "") {

for ( $i=1; $i<=$AttachNum; $i++) {

$Send->SendFile({description=>'邮件附件',

encoding=>'Base64',

disposition=>"attachment;filename=$AttachFileName[$i-1]",

file=>"$AttachDir$AttachFileName[$i-1]"});

}

}

$Send->Close;

#&print_head;

#print<<"EOF";

#$From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum,$SmtpSever

#EOF

#&print_foot;

if ($Send->{'error'} <0 ) {

mail_error('i',$Send->{'error'});

}

&ShowMailSuccess;

}

sub mail_error #3/24/00 4:24PM

{

my ($user,$errorCode)=@_;

&print_head;

($errorCode eq -1) and print "SMTP错误代码:-1";

($errorCode eq -2) and print "SMTP错误代码:-2";

($errorCode eq -3) and print "SMTP错误代码:-3";

($errorCode eq -4) and print "SMTP错误代码:-4";

($errorCode eq -5) and print "SMTP错误代码:-5";

($errorCode eq -6) and print "SMTP错误代码:-6";

($errorCode eq -7) and print "SMTP错误代码:-7";

($errorCode eq -8) and print "SMTP错误代码:-8";

($errorCode eq -9) and print "SMTP错误代码:-9";

($errorCode eq -10) and print "SMTP错误代码:-10";

($errorCode eq -11) and print "SMTP错误代码:-11";

($errorCode eq -12) and print "SMTP错误代码:-12";

&print_foot;

exit;

}

############################################################################

sub ShowMailSuccess #4/15/00 7:46PM

############################################################################

{

&print_head;

print<<"EOF";

成功发信

EOF

&print_foot;

exit;

} ##ShowMailSuccess

############################################################################

sub AttachFile #4/13/00 4:04PM

############################################################################

{

&ReadInput;

($AttachNum >= 3) and (ShowAttachForm($From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum,$AttachFile1,$AttachFile2,$AttachFile3,1));

my $AbsName = $NewFile;

$AbsName =~ s!^.*(\\|\/)!!;

open (FILE, ">$AttachDir$AbsName");

binmode(FILE);

while (my $bytesread = read($NewFile, my $buffer, 1024)) {

print FILE $buffer;

}

close (FILE);

$AttachFile .= $AbsName.';';

$AttachNum += 1;

if ($AttachNum eq 1) {$AttachFile1=$AbsName;}

if ($AttachNum eq 2) {$AttachFile2=$AbsName;}

if ($AttachNum eq 3) {$AttachFile3=$AbsName;}

ShowAttachForm($From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum,$AttachFile1,$AttachFile2,$AttachFile3,0);

}

############################################################################

sub ShowMailForm #4/13/00 4:50PM

############################################################################

{

#my ($From,$To,$Subject,$Cc,$Bcc,$AttachFile,$MailContent,$AttachNum) = @_;

&ReadInput;

&print_head;

print<<"EOF";

<form action="$ENV{'SCRIPT_NAME'}" align="center" method="post">

<input type="hidden" name="attachnum" value="$AttachNum"><input type="hidden" name="attachfile1"

value="$AttachFile1"><input type="hidden" name="attachfile2" value="$AttachFile2"><input

type="hidden" name="attachfile3" value="$AttachFile3">

<table border="0" cellpadding="0" cellspacing="0" width="69%">

<tr>

<td width="22%" align="right" bgcolor="#008000"><font color="#FFFFFF">发信人:</font></td>

<td width="78%" bgcolor="#F0FCC0"><input type="text" name="from" value="$From" size="38"></td>

</tr>

<tr>

<td width="22%" align="right" bgcolor="#008000"><font color="#FFFFFF">收件人:</font></td>

<td width="78%" bgcolor="#F0FCC0"><input type="text" name="to" value="$To" size="38"></td>

</tr>

<tr>

<td width="22%" align="right" bgcolor="#008000"><font color="#FFFFFF">主题:</font></td>

<td width="78%" bgcolor="#F0FCC0"><input type="text" name="subject" value="$Subject" size="38"></td>

</tr>

<tr>

<td width="22%" align="right" bgcolor="#008000"><font color="#FFFFFF">抄送:</font></td>

<td width="78%" bgcolor="#F0FCC0"><input type="text" name="cc" value="$Cc" size="38"></td>

</tr>

<tr>

<td width="22%" align="right" bgcolor="#008000"><font color="#FFFFFF">暗送:</font></td>

<td width="78%" bgcolor="#F0FCC0"><input type="text" name="bcc" value="$Bcc" size="38"></td>

</tr>

<tr>

<td width="22%" align="right" bgcolor="#008000"><font color="#FFFFFF">附件:</font></td>

<td width="78%" bgcolor="#F0FCC0"><input type="text" name="attachfile" value="$AttachFile"

size="38"></td>

</tr>

<tr>

<td width="22%" align="right">

</td>

<td width="78%" valign="bottom" align="left" ><input alt="发信" name="mailbutton"

src="$MailButton" type="image" > <input alt="附件" name="attachbutton"

src="$AttachButton" type="image" >

</td>

</tr>

<tr>

<td width="22%" align="right">邮件正文:</td>

<td width="78%"></td>

</tr>

<tr>

<td width="100%" colspan="2" align="center"><textarea rows="11" name="mailcontent" cols="47">$MailContent</textarea></td>

</tr>

</table>

</form>

EOF

&print_foot;

} ##ShowMailForm

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有