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"); 但是我認為分別賦值對于程序的編輯和閱讀更容易。>>
|