Cgi入门教程之:10 email子过程
点击次数:37 次 发布日期:2008-11-26 15:07:41 作者:源代码网
|
源代码网推荐#*****************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 Thank you goes on another line."; 源代码网推荐 为换行符 - 当双引号中包含 时,把它翻译成回车符。这对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 This is line 2"); 源代码网推荐但是我认为分别赋值对于程序的编辑和阅读更容易。>> 源代码网推荐 源代码网供稿. |
