email子过程
#*****************begin body*************
print "<h1>thank you for filling out the form</h1>";
$firstname = $value[0];
$lastname = $value[1];
$email = $value[2];
print "your first name is $firstname<br>";
print "your last name is $lastname<br>";
print "your e-mail is $email<br>";
$to = $email;
$from = "clinton\@whouse.gov";
$sub = "subject of my first e-mail";
$body = "the form was filled out by $firstname $lastname
thank you goes on another line.";
&email($to,$from,$sub,$body);
#***************end body******************
--------------------------------------------------------------------------------
在上面的例子中,我在程序的body后面增加了7行。你需要拷贝这些行到test2.cgi的body中。有两种方式:
在pc上的文本编辑器中进行拷贝和粘贴,然后用ftp重新上传,这时不必重新运行chmod。
可以在unix提示符下运行emacs或pico,对文件进行修改,然后保存和退出。
这时你可以再试试form。要在testform.htm页面中输入你自己的邮件地址。当你提交这个form时,显示结果与以前一样。但如果你在几秒种后查看你的e-mail,你会看到一封来自president clinton的消息。
让我们看看这些行:
$to = $email;
- 拷贝变量$email中的内容到变量$to中。
$from = "clinton\@whouse.gov";
- 设置变量$form为clinton@whouse.gov。反斜线(\)称为escape character。@符号在perl中有特殊意义,表示一个数组,这时,如果我们不想引用数组,而只用@符号本身,需要在前面加一个"\"。
例如,如果我敲入下面这行:
$amount = "he owes me $20.00";
将得到一个错误,因为perl将试图访问一个称为$20.00的变量。我们可以这样写:
$amount = "he owes me \$20.00";
$sub = "subject of my first e-mail";
这行很直接。
$body = "the form was filled out by $firstname $lastname thank you goes on another line.";
这只是一个命令 - perl命令总以分号结束。返回的字符是赋给$body的字符串中的另一个字符。这很方便,因为可以敲入引号,然后象在字处理器中一样敲入多行文本,然后用引号结束。最后,象其它语句一样敲入引号。
也可以象这样而得到相同的结果:
$body = "the form was filled out by $firstname $lastname \n thank you goes on another line.";
\n为换行符 - 当双引号中包含\n时,把它翻译成回车符。这对email也起作用 - 它是用ascii,而不是html写的。注意html不在意源代码是在一行还是在多行。如果想在html中加入一行,需要插入一个<br>或<p>标记符。
&email($to,$from,$sub,$body);
email子过程在下面的readparse子过程中定义。它被配置成很好用,只需简单地敲入
&email( addressee , reply-to, subject, message body)
例子中也可以这样传递参数:
&email($email,"clinton\@whouse.gov","subject of my first e-mail","this is line 1 \nthis is line 2");
但是我认为分别赋值对于程序的编辑和阅读更容易。>>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器