
- UID
- 2033152
- 威望
- 1 点
- 金钱
- 3090 金币
- 点卡
- 0 点
|
[转帖]怎样用perl编cgi发email
具体补充一下:- #!/usr/bin/perl
- # 请将下面邮箱改为您要接收反馈意见的邮箱,\@不要改动。
- $user_email = "你的邮箱\@后缀";
- $dd = `date`; chop $dd;
- $method = $ENV{"REQUEST_METHOD"};
- $type = $ENV{"CONTENT_TYPE"};
- $remoteip = $ENV{"REMOTE_ADDR"};
- if ($method ne "POST" || $type ne "application/x-www-form-urlencoded")
- {
- print "Location: http://当提交的时候返回的页面\n\n";
- exit;
- }
- %input_values = &break_input;
- $email = &normalize_query($input_values{"EMAIL"});
- $message = &normalize_query($input_values{"MESSAGE"});
- if ($message eq "") {
- $error_msg = "您没有留下意见!<BR>请按返回键再试一次!";
- exit &print_error();
- }
- if ($email eq "") {
- $error_msg = "您没有提供e-mail地址,<BR>请填好您的e-mail地址再试一次!";
- exit &print_error();
- }
- open(M,"|/usr/sbin/sendmail $user_email");
- # 用的open语法打开邮件管道/usr/sbin/sendmail,所以nt和os一般不行
- print M <<EOFX;
- From: $email
- To: $user_email
- Subject: 意见反馈
- Date: $dd
- E-mail: $email
- IP: $remoteip
- Message:
- $message
- EOFX
-
- close (M);
- $error_msg = "感谢您对我们提出的建议";
- &print_error();
- #####################
- # SUB-ROUTINES
- #####################
- sub break_input {
- local ($i);
- read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
- @form_names = split('&', $input);
- foreach $i (@form_names) {
- ($html_name, $html_value) = split('=', $i);
- $input_values{$html_name} = $html_value;
- }
- return %input_values;
- }
- sub normalize_query {
- local($value) = @_;
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- return $value;
- }
- sub print_error {
- print <<EOP;
- Content-type: text/html
- <html>
- <head>
- <title>message</title>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <style type="text/css">
- <!--
- .main {font-size: 12px}
- .main1{ font-size: 14.8px }
- .main2{ font-size: 16px }
- .main4{font-size: 10px}
- A:link {color: #333333; font-style: normal; text-decoration: underline}
- A:visited {color: #333333; font-style: normal; text-decoration: underline}
- A:active {color: #999999; font-style: normal; text-decoration: none}
- A:hover {color: #999999; font-style:bold; text-decoration: none}
- -->
- </style>
- </head>
- <body bgcolor="#FFFFFF" text="#666666" leftmargin="0" topmargin="0">
- <table width="100%" border="0" height="100%" cellpadding="0" cellspacing="0">
- <tr>
- <td>
- <table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#C6C6C6" align="center">
- <tr>
- <td>
- <table width="100%" border="0" cellspacing="1" cellpadding="0">
- <tr>
- <td bgcolor="#F8F8F8">
- <table width="100%" border="0">
- <tr>
- <td bgcolor="#e6e6e6">
- <div align="center" class="main2"><b>message</b></div>
- </td>
- </tr>
- <tr>
- <td height="20"></td>
- </tr>
- <tr>
- <td>
- <div align="center" class="main">$error_msg</div>
- </td>
- </tr>
- <tr>
- <td height="20"></td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
-
- <div align="center"><br>
- <input style='BORDER-RIGHT: #C6C6C6 1px solid; BORDER-TOP: #C6C6C6 1px solid; FONT-SIZE: 12px; BORDER-LEFT: #C6C6C6 1px solid; COLOR: #666666; BORDER-BOTTOM: #C6C6C6 1px solid; FONT-FAMILY: "宋体","Arial", "Helvetica", "sans-serif"; BACKGROUND-COLOR: #F8F8F8' type="button" value=" 返回 " onClick="javascript:history.back()" name="button">
- </div>
- </td>
- </tr>
- </table>
- </body>
- </html>
- EOP
- }
复制代码 |
|