Cgi入门教程之:10 email子过程

email子过程
#****BEGIN BODY
print "

1<h1>Thank you for filling out the form</h1>

";
$firstname = $value[0];
$lastname = $value[1];
$email = $value[2];

print "Your first name is $firstname

1<br/>

";
print "Your last name is $lastname

1<br/>

";
print "Your e-mail is $email

1<br/>

";
$to = $email;
$from = "[email protected]";
$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 = "[email protected]";
- 设置变量$form为[email protected]。反斜线(\)称为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中加入一行,需要插入一个

1<br/>

1<p>标记符。   
2&amp;email($to,$from,$sub,$body);   
3email子过程在下面的readparse子过程中定义。它被配置成很好用,只需简单地敲入   
4&amp;email( addressee , reply-to, subject, message body)   
5例子中也可以这样传递参数:   
6&amp;email($email,"clinton\@whouse.gov","subject of my first e-mail","This is line 1 \nThis is line 2");   
7但是我认为分别赋值对于程序的编辑和阅读更容易。&gt;&gt;</p>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus